Spaces:
Sleeping
Sleeping
File size: 706 Bytes
b5b5f5d f1b7a55 b5b5f5d f1b7a55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 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()
|