Spaces:
Runtime error
Runtime error
Timing0311
commited on
Commit
•
a88db4c
1
Parent(s):
bd27b28
test translation func
Browse files
app.py
CHANGED
@@ -1,17 +1,17 @@
|
|
1 |
-
from transformers import
|
2 |
import gradio as grad
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
10 |
return response
|
11 |
-
grad.
|
12 |
-
|
13 |
-
grad.Interface(
|
14 |
-
|
15 |
-
|
16 |
-
outputs=["html", "state"],
|
17 |
-
css=css).launch()
|
|
|
1 |
+
from transformers import MT5ForConditionalGeneration, AutoTokenizer
|
2 |
import gradio as grad
|
3 |
+
|
4 |
+
mdl = MT5ForConditionalGeneration.from_pretrained("google/mt5-small")
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
|
6 |
+
|
7 |
+
def translation_CN2EN(text):
|
8 |
+
inp = "translate English to Chinese:: "+text
|
9 |
+
enc = tokenizer(inp, return_tensors="pt")
|
10 |
+
tokens = mdl.generate(**enc)
|
11 |
+
response = tokenizer.batch_decode(tokens)
|
12 |
return response
|
13 |
+
para=grad.Textbox(lines=1, label="Chinese Text", placeholder="Text in Chinese")
|
14 |
+
out=grad.Textbox(lines=1, label="English Translation")
|
15 |
+
grad.Interface(translation_CN2EN, inputs=para, outputs=out).launch()
|
16 |
+
|
17 |
+
|
|
|
|