Spaces:
Running
Running
from transformers import pipeline | |
import gradio as gr | |
# Load built-in 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") | |
# Define 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'] | |
# Build Gradio UI | |
interface = gr.Interface( | |
fn=translate, | |
inputs=[ | |
gr.Textbox(lines=5, label="Enter text"), | |
gr.Dropdown(["English to Urdu", "Urdu to English"], label="Direction") | |
], | |
outputs=gr.Textbox(label="Translated Text"), | |
title="English β Urdu Translator", | |
description="Translate text between English and Urdu using Hugging Face models." | |
) | |
# Launch the app | |
interface.launch() | |