girol5 / app.py
prol99's picture
Upload app.py
c403a51 verified
raw
history blame
1.09 kB
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
# Cargar el tokenizador y el modelo correctamente
tokenizer = AutoTokenizer.from_pretrained("projecte-aina/aina-translator-es-ast")
model = AutoModelForSeq2SeqLM.from_pretrained("projecte-aina/aina-translator-es-ast")
# Crear el pipeline de traducción
translator = pipeline("translation", model=model, tokenizer=tokenizer)
# Función de chatbot que traduce automáticamente
def chatbot_response(message, chat_history):
translation = translator(message, max_length=200)[0]['translation_text']
chat_history.append((message, translation))
return "", chat_history
# Crear interfaz en Gradio
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")
# Configuración del botón de envío
send_btn.click(fn=chatbot_response, inputs=[msg, chatbot], outputs=[msg, chatbot])
# Lanzar la aplicación
demo.launch()