import gradio as gr | |
from transformers import pipeline | |
# Load the English to Urdu translation model from the transformers library | |
model_name_or_path = "Helsinki-NLP/opus-mt-en-ur" | |
translator = pipeline("translation", model=model_name_or_path, tokenizer=model_name_or_path) | |
# Create a Gradio interface for the translation app | |
def translate(text): | |
# Use the translator pipeline to translate the input text | |
result = translator(text, max_length=500) | |
return result[0]['translation_text'] | |
input_text = gr.inputs.Textbox(label="Input English Text") | |
output_text = gr.outputs.Textbox(label="Output Urdu Text") | |
app = gr.Interface(fn=translate, inputs=input_text, outputs=output_text) | |
# Launch the app | |
app.launch() | |