Girol9 / appxxxx.py
prol99's picture
Rename app.py to appxxxx.py
c30cb3a verified
import gradio as gr
from transformers import AutoTokenizer, MarianMTModel, pipeline
def translate_text(text):
"""
Traduce texto del espa帽ol al asturiano
"""
try:
if not text:
return ""
# Crear el pipeline de traducci贸n
translator = pipeline(
"translation",
model="projecte-aina/aina-translator-es-ast",
src_lang="es",
tgt_lang="ast"
)
# Realizar la traducci贸n
result = translator(text, max_length=512)
translation = result[0]['translation_text']
print(f"Texto original: {text}") # Debug
print(f"Traducci贸n: {translation}") # Debug
return translation
except Exception as e:
print(f"Error durante la traducci贸n: {str(e)}") # Debug
return f"Error en la traducci贸n: {str(e)}"
# Crear la interfaz Gradio
demo = gr.Interface(
fn=translate_text,
inputs=gr.Textbox(label="Texto en espa帽ol", placeholder="Escribe aqu铆 el texto a traducir..."),
outputs=gr.Textbox(label="Traducci贸n al asturiano"),
title="Traductor Espa帽ol-Asturiano",
description="Traductor basado en el modelo AINA para traducir del espa帽ol al asturiano.",
examples=[
["Hola, 驴c贸mo est谩s?"],
["Me gusta mucho Asturias y su cultura"],
["El cielo est谩 muy azul hoy"]
]
)
# Lanzar la aplicaci贸n
if __name__ == "__main__":
demo.launch(debug=True)