File size: 862 Bytes
1ad14b0
1d64def
 
ef31d2e
553c9a8
1d64def
63267a9
b39033e
ef31d2e
553c9a8
1ad14b0
1d64def
 
 
63267a9
 
 
1d64def
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

import gradio as gr
from transformers import pipeline
#from fairseq.models.transformer import TransformerModel


# Load the English to Urdu translation model from the transformers library
model_name_or_path = "Helsinki-NLP/opus-mt-en-ur"
#model_name_or_path = TransformerModel.from_pretrained('samiulhaq/iwslt-bt-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()