Spaces:
Runtime error
Runtime error
japanese-denim
commited on
Commit
•
59fd7cf
1
Parent(s):
bb89ea3
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,31 @@
|
|
1 |
-
import
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
2 |
+
import torch
|
3 |
|
4 |
+
model_checkpoint = "japanese-denim/mbart-50-finetuned-eng-to-naga"
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
7 |
+
|
8 |
+
|
9 |
+
src_lang = 'en_XX'
|
10 |
+
tgt_lang = "ng_XX"
|
11 |
+
|
12 |
+
|
13 |
+
def translate(text):
|
14 |
+
translation_pipeline = pipeline("translation",
|
15 |
+
model=model,
|
16 |
+
tokenizer=tokenizer,
|
17 |
+
src_lang=src_lang,
|
18 |
+
tgt_lang=tgt_lang)
|
19 |
+
|
20 |
+
result = translation_pipeline(text)
|
21 |
+
return result[0]['translation_text']
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
gr.Interface(
|
26 |
+
translate,
|
27 |
+
[
|
28 |
+
gr.components.Textbox(label="input", placeholder = " Enter English sentence here")
|
29 |
+
],
|
30 |
+
["text"],
|
31 |
+
).launch()
|