Upload app.py
Browse files
app.py
CHANGED
|
@@ -4,21 +4,16 @@ from transformers import pipeline
|
|
| 4 |
# Cargar el modelo de traducción
|
| 5 |
translator = pipeline("translation", model="projecte-aina/aina-translator-es-ast")
|
| 6 |
|
| 7 |
-
# Función de chatbot
|
| 8 |
def chatbot_response(message, chat_history):
|
| 9 |
-
|
| 10 |
-
chat_history.append((message,
|
| 11 |
return "", chat_history
|
| 12 |
|
| 13 |
-
# Crear interfaz
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
gr.Markdown("# 🤖 Chatbot Traductor Español → Asturiano")
|
| 16 |
|
| 17 |
chatbot = gr.Chatbot()
|
| 18 |
msg = gr.Textbox(label="Escribe tu mensaje en Español...")
|
| 19 |
-
send_btn = gr.Button("
|
| 20 |
-
|
| 21 |
-
send_btn.click(chatbot_response, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 22 |
-
|
| 23 |
-
# Lanzar la aplicación
|
| 24 |
-
demo.launch()
|
|
|
|
| 4 |
# Cargar el modelo de traducción
|
| 5 |
translator = pipeline("translation", model="projecte-aina/aina-translator-es-ast")
|
| 6 |
|
| 7 |
+
# Función de chatbot que traduce automáticamente
|
| 8 |
def chatbot_response(message, chat_history):
|
| 9 |
+
translation = translator(message, max_length=200)[0]['translation_text']
|
| 10 |
+
chat_history.append((message, translation))
|
| 11 |
return "", chat_history
|
| 12 |
|
| 13 |
+
# Crear interfaz en Gradio
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
gr.Markdown("# 🤖 Chatbot Traductor Español → Asturiano")
|
| 16 |
|
| 17 |
chatbot = gr.Chatbot()
|
| 18 |
msg = gr.Textbox(label="Escribe tu mensaje en Español...")
|
| 19 |
+
send_btn = gr.Button("Envia
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|