Spaces:
Sleeping
Sleeping
Commit
·
2d5275e
1
Parent(s):
8fb770d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
model_checkpoint = "japanese-denim/mbart-50-finetuned-naga-to-eng"
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
8 |
+
|
9 |
+
def translate(text):
|
10 |
+
translation_pipeline = pipeline("translation",
|
11 |
+
model=model,
|
12 |
+
tokenizer = tokenizer,
|
13 |
+
src_lang='ng_XX',
|
14 |
+
tgt_lang='en_XX')
|
15 |
+
|
16 |
+
result = translation_pipeline(text)
|
17 |
+
return result[0]['translation_text']
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
gr.Interface(
|
22 |
+
translate,
|
23 |
+
[
|
24 |
+
gr.components.Textbox(label="input", placeholder = "Enter Nagamese sentence here")
|
25 |
+
],
|
26 |
+
["text"],
|
27 |
+
).launch()
|