Spaces:
Sleeping
Sleeping
| # π English β Urdu Translation App (Test in Colab) | |
| # Import libraries | |
| import gradio as gr | |
| from transformers import pipeline | |
| # Load models | |
| en_to_ur = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ur") | |
| ur_to_en = pipeline("translation", model="Helsinki-NLP/opus-mt-ur-en") | |
| # Translation function | |
| def translate(text, direction): | |
| if direction == "English to Urdu": | |
| return en_to_ur(text)[0]['translation_text'] | |
| else: | |
| return ur_to_en(text)[0]['translation_text'] | |
| # Gradio interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## π English β Urdu Translator using Hugging Face") | |
| with gr.Row(): | |
| input_text = gr.Textbox(label="Enter text", placeholder="Type here...") | |
| direction = gr.Radio(["English to Urdu", "Urdu to English"], label="Direction", value="English to Urdu") | |
| output_text = gr.Textbox(label="Translated text") | |
| translate_button = gr.Button("Translate") | |
| translate_button.click(fn=translate, inputs=[input_text, direction], outputs=output_text) | |
| # Launch app | |
| demo.launch() | |