Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| import gradio as gr | |
| # Load translation pipelines once | |
| t5_translator = pipeline("translation_en_to_de", model="t5-small") | |
| # β Correct and public model for English β Tamil | |
| ta_translator = pipeline("translation_en_to_ta", model="Helsinki-NLP/opus-mt-en-tam") | |
| def translate_text(text): | |
| # Translate using T5-small (English β German) | |
| result_t5 = t5_translator(text, max_length=40)[0]['translation_text'] | |
| # Translate using Helsinki-NLP (English β Tamil) | |
| result_ta = ta_translator(text, max_length=40)[0]['translation_text'] | |
| return result_t5, result_ta | |
| # Create Gradio interface | |
| demo = gr.Interface( | |
| fn=translate_text, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter English text here..."), | |
| outputs=[ | |
| gr.Textbox(label="T5-small Translation (English β German)"), | |
| gr.Textbox(label="Helsinki-NLP Translation (English β Tamil)") | |
| ], | |
| title="π Text Translator", | |
| description="Enter English text and get translations using T5-small (English β German) and Helsinki-NLP (English β Tamil)" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |