File size: 753 Bytes
a8c87aa 398511e a8c87aa 398511e a8c87aa 398511e a8c87aa 398511e a8c87aa 398511e |
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 |
import gradio as gr
from transformers import pipeline
# ID de tu modelo en Hugging Face (público)
MODEL_ID = "alramil/opus-mt-en-es-books"
# Creamos el pipeline de traducción
translator = pipeline("text2text-generation", model=MODEL_ID)
def translate_text(text):
result = translator(
text,
max_length=128,
clean_up_tokenization_spaces=True
)
return result[0]["generated_text"]
demo = gr.Interface(
fn=translate_text,
inputs=gr.Textbox(lines=5, label="Texto en inglés"),
outputs=gr.Textbox(label="Traducción al español"),
title="Traductor Inglés → Español",
description="Escribe o pega aquí tu texto en inglés y obtén la traducción."
)
if __name__ == "__main__":
demo.launch() |