Download app.py from alramil/Practica8: direct link, hf CLI and curl.
- Browser
- Download file 753 Bytes
-
https://huggingface.co/spaces/alramil/Practica8/resolve/main/app.py
- Command line
-
hf download hf://spaces/alramil/Practica8/app.py
-
curl -L -o app.py https://huggingface.co/spaces/alramil/Practica8/resolve/main/app.py
753 Bytes
| 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() |