Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def translate_text(text):
|
| 8 |
-
result = translator(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
return result[0]["generated_text"]
|
| 10 |
|
| 11 |
-
|
| 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
|
| 16 |
-
description="
|
| 17 |
)
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
| 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és → Españ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()
|