# Import necessary modules import gradio as gr from transformers import MarianMTModel, MarianTokenizer # Load the English to Urdu translation model model_name = "Helsinki-NLP/opus-mt-en-ur" tokenizer = MarianTokenizer.from_pretrained(model_name) model = MarianMTModel.from_pretrained(model_name) # Define the translation function def translate(text): inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True) translated = model.generate(**inputs) output = tokenizer.decode(translated[0], skip_special_tokens=True) return output # Create the Gradio interface iface = gr.Interface( fn=translate, inputs=gr.Textbox(lines=1, placeholder="Enter your (English) text here..."), outputs=gr.Textbox(label="Translation (Urdu)"), title="English to Urdu Translator", description="Enter text in English and get the Urdu translation instantly." ) # Launch the app iface.launch()