Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,47 @@
|
|
1 |
|
2 |
-
import gradio as gr
|
3 |
-
from transformers import pipeline
|
4 |
#from fairseq.models.transformer import TransformerModel
|
5 |
|
6 |
|
7 |
# Load the English to Urdu translation model from the transformers library
|
8 |
-
model_name_or_path = "Helsinki-NLP/opus-mt-en-ur"
|
9 |
#model_name_or_path = TransformerModel.from_pretrained('samiulhaq/iwslt-bt-en-ur')
|
10 |
|
11 |
-
translator = pipeline("translation", model=model_name_or_path, tokenizer=model_name_or_path)
|
12 |
|
13 |
# Create a Gradio interface for the translation app
|
14 |
-
def translate(text):
|
15 |
# Use the translator pipeline to translate the input text
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
input_text = gr.inputs.Textbox(label="Input English Text")
|
20 |
output_text = gr.outputs.Textbox(label="Output Urdu Text")
|
@@ -22,3 +49,4 @@ app = gr.Interface(fn=translate, inputs=input_text, outputs=output_text)
|
|
22 |
|
23 |
# Launch the app
|
24 |
app.launch()
|
|
|
|
1 |
|
2 |
+
#import gradio as gr
|
3 |
+
#from transformers import pipeline
|
4 |
#from fairseq.models.transformer import TransformerModel
|
5 |
|
6 |
|
7 |
# Load the English to Urdu translation model from the transformers library
|
8 |
+
#model_name_or_path = "Helsinki-NLP/opus-mt-en-ur"
|
9 |
#model_name_or_path = TransformerModel.from_pretrained('samiulhaq/iwslt-bt-en-ur')
|
10 |
|
11 |
+
#translator = pipeline("translation", model=model_name_or_path, tokenizer=model_name_or_path)
|
12 |
|
13 |
# Create a Gradio interface for the translation app
|
14 |
+
#def translate(text):
|
15 |
# Use the translator pipeline to translate the input text
|
16 |
+
# result = translator(text, max_length=500)
|
17 |
+
# return result[0]['translation_text']
|
18 |
+
|
19 |
+
#input_text = gr.inputs.Textbox(label="Input English Text")
|
20 |
+
#output_text = gr.outputs.Textbox(label="Output Urdu Text")
|
21 |
+
#app = gr.Interface(fn=translate, inputs=input_text, outputs=output_text)
|
22 |
+
|
23 |
+
# Launch the app
|
24 |
+
#app.launch()
|
25 |
+
|
26 |
+
|
27 |
+
import gradio as gr
|
28 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
29 |
+
|
30 |
+
# Load the English to Urdu translation model from the transformers library
|
31 |
+
model_name_or_path = "aryanc55/english-urdu"
|
32 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
33 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_or_path)
|
34 |
+
|
35 |
+
# Create a Gradio interface for the translation app
|
36 |
+
def translate(text):
|
37 |
+
# Tokenize the input text
|
38 |
+
inputs = tokenizer(text, return_tensors="pt")
|
39 |
+
|
40 |
+
# Use the model to generate the translated text
|
41 |
+
outputs = model.generate(inputs["input_ids"], max_length=500, early_stopping=True)
|
42 |
+
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
43 |
+
|
44 |
+
return translated_text
|
45 |
|
46 |
input_text = gr.inputs.Textbox(label="Input English Text")
|
47 |
output_text = gr.outputs.Textbox(label="Output Urdu Text")
|
|
|
49 |
|
50 |
# Launch the app
|
51 |
app.launch()
|
52 |
+
|