Spaces:
Runtime error
Runtime error
| # app.py | |
| import gradio as gr | |
| from transformers import pipeline | |
| # 1. Load a translation pipeline. | |
| # By default this is English → French; swap model for other language pairs. | |
| translator = pipeline("translation_en_to_fr", model="Helsinki-NLP/opus-mt-en-fr") | |
| def translate(text: str) -> str: | |
| """ | |
| Translate input English text into French. | |
| """ | |
| # The pipeline returns a list of dicts; we grab the 'translation_text' | |
| result = translator(text, max_length=512) | |
| return result[0]["translation_text"] | |
| # 2. Create the Gradio interface. | |
| iface = gr.Interface( | |
| fn=translate, | |
| inputs=gr.Textbox(lines=5, label="Input Text (English)"), | |
| outputs=gr.Textbox(lines=5, label="Translated Text (French)"), | |
| title="HuggingFace Translation Service", | |
| description="Enter English text and get a French translation powered by a Hugging Face model." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |