File size: 1,495 Bytes
f38f412 9adf5ac f38f412 253e06f 60e80b2 9adf5ac 60e80b2 9adf5ac 60e80b2 253e06f 60e80b2 f38f412 253e06f 9adf5ac 253e06f f38f412 253e06f 60e80b2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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) |