File size: 1,829 Bytes
1ad14b0 99d7a63 ef31d2e 553c9a8 1d64def 63267a9 99d7a63 ef31d2e 553c9a8 99d7a63 1d64def 99d7a63 63267a9 99d7a63 1d64def 99d7a63 |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#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()
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load the English to Urdu translation model from the transformers library
model_name_or_path = "aryanc55/english-urdu"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_or_path)
# Create a Gradio interface for the translation app
def translate(text):
# Tokenize the input text
inputs = tokenizer(text, return_tensors="pt")
# Use the model to generate the translated text
outputs = model.generate(inputs["input_ids"], max_length=500, early_stopping=True)
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return translated_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()
|