File size: 713 Bytes
1452a09
af5468d
1452a09
af5468d
 
1452a09
af5468d
 
 
 
1452a09
af5468d
 
 
 
 
 
 
 
1452a09
af5468d
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()