Add application file
Browse files
app.py
CHANGED
@@ -2,15 +2,37 @@
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
import os
|
5 |
-
translator = pipeline("translation", model=os.path.join(os.getcwd(),"test-ml-trained"), max_time=5)
|
6 |
|
7 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
pres=[]
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
print(name,pre)
|
13 |
-
return pres
|
14 |
-
|
15 |
-
|
16 |
-
interface.
|
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
import os
|
|
|
5 |
|
6 |
+
# def test(text):
|
7 |
+
# return text
|
8 |
+
# inputs=gr.TextArea(lines=10,label='请输入英文字段名',placeholder='以换行\\n为分隔符')
|
9 |
+
# outputs=gr.TextArea(lines=10,label='转译结果')
|
10 |
+
# interface = gr.Interface(fn=test, inputs=inputs, outputs=outputs)
|
11 |
+
# interface.launch()
|
12 |
+
|
13 |
+
# translator = pipeline("translation", model=os.path.join(os.getcwd(),"test-ml-trained"), max_time=5)
|
14 |
+
# # list-list
|
15 |
+
# def en2zh(EnNames):
|
16 |
+
# pres=[]
|
17 |
+
# for name in EnNames:
|
18 |
+
# pre = translator(name[0].replace('_',' '), )[0]["translation_text"]
|
19 |
+
# pres.append([pre])
|
20 |
+
# print(name,pre)
|
21 |
+
# return pres
|
22 |
+
# interface = gr.Interface(fn=en2zh, inputs="list", outputs="list")
|
23 |
+
# interface.launch()
|
24 |
+
|
25 |
+
translator = pipeline("translation", model=os.path.join(os.getcwd(),"test-ml-trained"), max_time=5)
|
26 |
+
# text-text
|
27 |
+
def en2zh(text):
|
28 |
pres=[]
|
29 |
+
enNames=text.split('\n')
|
30 |
+
for name in enNames:
|
31 |
+
pre = translator(name.replace('_',' '), )[0]["translation_text"]
|
32 |
+
pres.append(pre)
|
33 |
print(name,pre)
|
34 |
+
return '\n'.join(pres)
|
35 |
+
inputs=gr.TextArea(lines=10,label='请输入英文字段名',placeholder='以换行\\n为分隔符')
|
36 |
+
outputs=gr.TextArea(lines=10,label='转译结果')
|
37 |
+
interface = gr.Interface(fn=en2zh, inputs=inputs, outputs=outputs)
|
38 |
+
interface.launch()
|