Spaces:
Runtime error
Runtime error
guptavipin
commited on
Commit
•
58de6bb
1
Parent(s):
48501ce
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,17 @@
|
|
1 |
-
import gradio as gr
|
2 |
|
3 |
-
gr.load("models/balaramas/mbart-large-finetune-eng-hin").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import gradio as gr
|
2 |
|
3 |
+
# gr.load("models/balaramas/mbart-large-finetune-eng-hin").launch()
|
4 |
+
|
5 |
+
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
6 |
+
article_en = "The head of the United Nations says there is no military solution in Syria"
|
7 |
+
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
|
8 |
+
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_lang="en_XX")
|
9 |
+
|
10 |
+
model_inputs = tokenizer(article_en, return_tensors="pt")
|
11 |
+
|
12 |
+
# translate from English to Hindi
|
13 |
+
generated_tokens = model.generate(
|
14 |
+
**model_inputs,
|
15 |
+
forced_bos_token_id=tokenizer.lang_code_to_id["hi_IN"]
|
16 |
+
)
|
17 |
+
tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|