Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|