Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,18 @@
|
|
1 |
-
from transformers import AutoModelForSeq2SeqLM,
|
2 |
import gradio as grad
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
#opus_translator = pipeline("translation", model=
|
9 |
|
10 |
def translate(text):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
grad.Interface(translate, inputs=["text"], outputs=["text"]).launch()
|
|
|
1 |
+
from transformers import AutoModelForSeq2SeqLM,AutoTokenizer
|
2 |
import gradio as grad
|
3 |
|
4 |
+
mdl_name = "Helsinki-NLP/opus-mt-ko-en"
|
5 |
+
mdl = AutoModelForSeq2SeqLM.from_pretrained(mdl_name)
|
6 |
+
my_tkn = AutoTokenizer.from_pretrained(mdl_name)
|
7 |
|
8 |
+
#opus_translator = pipeline("translation", model=mdl_name)
|
9 |
|
10 |
def translate(text):
|
11 |
+
inputs = my_tkn(text, return_tensors="pt")
|
12 |
+
trans_output = mdl.generate(**inputs)
|
13 |
+
response = my_tkn.decode(trans_output[0], skip_special_tokens=True)
|
14 |
|
15 |
+
#response = opus_translator(text)
|
16 |
+
return response
|
17 |
|
18 |
+
grad.Interface(translate, inputs=["text",], outputs="text").launch()
|
|