|
|
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 "" |
|
|
|
|
|
|
|
|
translator = pipeline( |
|
|
"translation", |
|
|
model="projecte-aina/aina-translator-es-ast", |
|
|
src_lang="es", |
|
|
tgt_lang="ast" |
|
|
) |
|
|
|
|
|
|
|
|
result = translator(text, max_length=512) |
|
|
translation = result[0]['translation_text'] |
|
|
|
|
|
print(f"Texto original: {text}") |
|
|
print(f"Traducci贸n: {translation}") |
|
|
|
|
|
return translation |
|
|
|
|
|
except Exception as e: |
|
|
print(f"Error durante la traducci贸n: {str(e)}") |
|
|
return f"Error en la traducci贸n: {str(e)}" |
|
|
|
|
|
|
|
|
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"] |
|
|
] |
|
|
) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch(debug=True) |