space3 / app.py
sohailq's picture
Update app.py
b39033e
raw
history blame
862 Bytes
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()