File size: 545 Bytes
88047cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
from transformers import pipeline

# Load the translation pipeline from Hugging Face
translator = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")

# Define the translation function
def translate(text):
    translated = translator(text)
    return translated[0]['translation_text']

# Create the Gradio interface
interface = gr.Interface(
    fn=translate,
    inputs=gr.Textbox(label="Enter text in English"),
    outputs=gr.Textbox(label="Translated text in Urdu")
)

# Launch the app
interface.launch()