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()