translation / app.py
Naz786's picture
Update app.py
f1b7a55 verified
raw
history blame
706 Bytes
import gradio as gr
from transformers import pipeline
# Load the translation pipeline
translator = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
def translate_text(text):
if not text.strip():
return "Please enter some text."
translated = translator(text)
return translated[0]['translation_text']
# Gradio Interface
iface = gr.Interface(
fn=translate_text,
inputs=gr.Textbox(lines=5, placeholder="Enter text in English..."),
outputs=gr.Textbox(label="Translated Text in Urdu"),
title="English to Urdu Translator",
description="Enter English text and get its Urdu translation instantly."
)
if __name__ == "__main__":
iface.launch()