Translation / app.py
sunbal7's picture
Update app.py
af5468d verified
raw
history blame contribute delete
713 Bytes
import gradio as gr
from transformers import pipeline
# Load the pre-trained translation model
translator = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
# Translation function
def translate_text(text):
translation = translator(text, max_length=400)
return translation[0]['translation_text']
# Gradio interface
interface = gr.Interface(
fn=translate_text,
inputs=gr.Textbox(lines=2, placeholder="Enter English text here..."),
outputs=gr.Textbox(lines=2, label="Urdu Translation"),
title="English to Urdu Translation",
description="Translate English text to Urdu using a pre-trained model."
)
# Launch the app
if __name__ == "__main__":
interface.launch()