alramil commited on
Commit
398511e
·
verified ·
1 Parent(s): a8c87aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -1,19 +1,27 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- model_id = "alramil/opus-mt-en-es-books"
5
- translator = pipeline("text2text-generation", model=model_id)
 
 
 
6
 
7
  def translate_text(text):
8
- result = translator(text, max_length=128, clean_up_tokenization_spaces=True)
 
 
 
 
9
  return result[0]["generated_text"]
10
 
11
- interface = gr.Interface(
12
  fn=translate_text,
13
  inputs=gr.Textbox(lines=5, label="Texto en inglés"),
14
  outputs=gr.Textbox(label="Traducción al español"),
15
- title="Traductor Inglés-Español",
16
- description="Introduce texto en inglés."
17
  )
18
 
19
- interface.launch()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # ID de tu modelo en Hugging Face (público)
5
+ MODEL_ID = "alramil/opus-mt-en-es-books"
6
+
7
+ # Creamos el pipeline de traducción
8
+ translator = pipeline("text2text-generation", model=MODEL_ID)
9
 
10
  def translate_text(text):
11
+ result = translator(
12
+ text,
13
+ max_length=128,
14
+ clean_up_tokenization_spaces=True
15
+ )
16
  return result[0]["generated_text"]
17
 
18
+ demo = gr.Interface(
19
  fn=translate_text,
20
  inputs=gr.Textbox(lines=5, label="Texto en inglés"),
21
  outputs=gr.Textbox(label="Traducción al español"),
22
+ title="Traductor InglésEspañol",
23
+ description="Escribe o pega aquí tu texto en inglés y obtén la traducción."
24
  )
25
 
26
+ if __name__ == "__main__":
27
+ demo.launch()