prol99 commited on
Commit
f58a040
·
verified ·
1 Parent(s): c403a51

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +14 -24
  2. requirements.txt +4 -2
app.py CHANGED
@@ -1,29 +1,19 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
 
4
- # Cargar el tokenizador y el modelo correctamente
5
- tokenizer = AutoTokenizer.from_pretrained("projecte-aina/aina-translator-es-ast")
6
- model = AutoModelForSeq2SeqLM.from_pretrained("projecte-aina/aina-translator-es-ast")
7
 
8
- # Crear el pipeline de traducción
9
- translator = pipeline("translation", model=model, tokenizer=tokenizer)
 
10
 
11
- # Función de chatbot que traduce automáticamente
12
- def chatbot_response(message, chat_history):
13
- translation = translator(message, max_length=200)[0]['translation_text']
14
- chat_history.append((message, translation))
15
- return "", chat_history
 
16
 
17
- # Crear interfaz en Gradio
18
- with gr.Blocks() as demo:
19
- gr.Markdown("# 🤖 Chatbot Traductor Español → Asturiano")
20
-
21
- chatbot = gr.Chatbot()
22
- msg = gr.Textbox(label="Escribe tu mensaje en Español...")
23
- send_btn = gr.Button("Enviar")
24
-
25
- # Configuración del botón de envío
26
- send_btn.click(fn=chatbot_response, inputs=[msg, chatbot], outputs=[msg, chatbot])
27
-
28
- # Lanzar la aplicación
29
- demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Cargar el modelo
5
+ model = pipeline("translation", model="projecte-aina/aina-translator-es-ast")
 
6
 
7
+ # Función para traducir
8
+ def translate(text):
9
+ return model(text)[0]['translation_text']
10
 
11
+ # Crear la interfaz de Gradio
12
+ interface = gr.Interface(
13
+ fn=translate,
14
+ inputs=gr.Textbox(label="Texto en español"),
15
+ outputs=gr.Textbox(label="Traducción al asturiano")
16
+ )
17
 
18
+ # Lanzar la interfaz
19
+ interface.launch(debug=True, share=True)
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,4 +1,6 @@
1
- huggingface_hub==0.25.2
2
  transformers
3
- torch
4
  gradio
 
 
 
 
 
 
1
  transformers
 
2
  gradio
3
+ torch
4
+ torchvision
5
+ torchaudio
6
+ sentencepiece