Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
translator = pipeline("
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
# Crear la interfaz
|
| 13 |
-
|
| 14 |
-
fn=
|
| 15 |
-
inputs=gr.Textbox(
|
| 16 |
-
outputs="
|
| 17 |
-
title="Traductor Espa帽ol
|
| 18 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
# Lanzar la aplicaci贸n
|
| 22 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Inicializar el modelo de traducci贸n
|
| 5 |
+
translator = pipeline("translation", model="projecte-aina/aina-translator-es-ast")
|
| 6 |
|
| 7 |
+
def translate_text(text):
|
| 8 |
+
"""
|
| 9 |
+
Traduce texto del espa帽ol al asturiano
|
| 10 |
+
"""
|
| 11 |
+
if not text:
|
| 12 |
+
return ""
|
| 13 |
+
|
| 14 |
+
result = translator(text, max_length=400)
|
| 15 |
+
return result[0]['translation_text']
|
| 16 |
|
| 17 |
+
# Crear la interfaz Gradio
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=translate_text,
|
| 20 |
+
inputs=gr.Textbox(label="Texto en espa帽ol", placeholder="Escribe aqu铆 el texto a traducir..."),
|
| 21 |
+
outputs=gr.Textbox(label="Traducci贸n al asturiano"),
|
| 22 |
+
title="Traductor Espa帽ol-Asturiano",
|
| 23 |
+
description="Traductor basado en el modelo AINA para traducir del espa帽ol al asturiano.",
|
| 24 |
+
examples=[
|
| 25 |
+
["Hola, 驴c贸mo est谩s?"],
|
| 26 |
+
["Me gusta mucho Asturias y su cultura"],
|
| 27 |
+
["El cielo est谩 muy azul hoy"]
|
| 28 |
+
]
|
| 29 |
)
|
| 30 |
|
| 31 |
# Lanzar la aplicaci贸n
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
demo.launch()
|