|
|
import gradio as gr |
|
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline |
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("projecte-aina/aina-translator-es-ast") |
|
|
model = AutoModelForSeq2SeqLM.from_pretrained("projecte-aina/aina-translator-es-ast") |
|
|
|
|
|
|
|
|
translator = pipeline("translation", model=model, tokenizer=tokenizer) |
|
|
|
|
|
|
|
|
def chatbot_response(message, chat_history): |
|
|
translation = translator(message, max_length=200)[0]['translation_text'] |
|
|
chat_history.append((message, translation)) |
|
|
return "", chat_history |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# 🤖 Chatbot Traductor Español → Asturiano") |
|
|
|
|
|
chatbot = gr.Chatbot() |
|
|
msg = gr.Textbox(label="Escribe tu mensaje en Español...") |
|
|
send_btn = gr.Button("Enviar") |
|
|
|
|
|
|
|
|
send_btn.click(fn=chatbot_response, inputs=[msg, chatbot], outputs=[msg, chatbot]) |
|
|
|
|
|
|
|
|
demo.launch() |
|
|
|