Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
|
4 |
-
# Load the
|
5 |
-
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
# Create the Gradio interface
|
17 |
iface = gr.Interface(
|
18 |
-
fn=
|
19 |
-
inputs=gr.Textbox(label="
|
20 |
-
outputs=gr.Textbox(label="
|
21 |
-
title="English
|
22 |
-
description="
|
23 |
-
theme="default"
|
24 |
)
|
25 |
|
26 |
# Launch the app
|
27 |
-
|
28 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
|
3 |
|
4 |
+
# Load the fine-tuned model
|
5 |
+
model_name = "abdulwaheed1/urdu_to_english_translation_mbart"
|
6 |
+
tokenizer = MBart50TokenizerFast.from_pretrained(model_name, src_lang="ur_PK", tgt_lang="en_XX")
|
7 |
+
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
8 |
|
9 |
+
def translate_urdu_to_english(text):
|
10 |
+
# Tokenize the input text
|
11 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
12 |
+
# Generate translation
|
13 |
+
outputs = model.generate(**inputs)
|
14 |
+
# Decode the translated text
|
15 |
+
translation = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
16 |
+
return translation
|
17 |
|
18 |
# Create the Gradio interface
|
19 |
iface = gr.Interface(
|
20 |
+
fn=translate_urdu_to_english,
|
21 |
+
inputs=gr.inputs.Textbox(label="Input Urdu Text"),
|
22 |
+
outputs=gr.outputs.Textbox(label="Translated English Text"),
|
23 |
+
title="Urdu to English Translation",
|
24 |
+
description="Enter Urdu text to get the English translation."
|
|
|
25 |
)
|
26 |
|
27 |
# Launch the app
|
28 |
+
iface.launch()
|
|