maxmon
commited on
Commit
•
c0116dd
1
Parent(s):
f03c9a2
refactor: app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
if need_trans:
|
6 |
txt = en2cn(txt)
|
|
|
7 |
if radio == '文本分类':
|
8 |
result = text_classification(txt, types)
|
9 |
if radio == '实体抽取':
|
@@ -18,18 +24,6 @@ output = gr.Textbox(label="输出结果")
|
|
18 |
radio = gr.Radio(["文本分类", "实体抽取"], label="算法类型")
|
19 |
checkbox = gr.Checkbox(label="翻译成中文")
|
20 |
|
21 |
-
# 读取数据
|
22 |
-
from utils.anno.cls.text_classification import text_classification
|
23 |
-
from utils.anno.ner.entity_extract import extract_named_entities
|
24 |
-
from utils.api.google_trans import en2cn
|
25 |
-
|
26 |
if __name__ == '__main__':
|
27 |
-
# # 多文本分类
|
28 |
-
# txts = open('data/cls/jd.csv', 'r', encoding='utf-8').read().split('\n')[1:]
|
29 |
-
# txts = [txt.split(',')[0] for txt in txts if txt != '']
|
30 |
-
|
31 |
-
# results = []
|
32 |
-
# for txt in txts:
|
33 |
-
# results.append(text_classification(txt, ['好评', '差评']))
|
34 |
demo = gr.Interface(fn=auto_anno, inputs=[input1, input2, radio, checkbox], outputs=[output])
|
35 |
demo.launch(share=False)
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
|
4 |
+
from utils.anno.cls.text_classification import text_classification
|
5 |
+
from utils.anno.ner.entity_extract import extract_named_entities
|
6 |
+
from utils.api.google_trans import en2cn
|
7 |
+
from utils.format.txt_2_list import txt_2_list
|
8 |
+
|
9 |
+
def auto_anno(txt, types_txt, radio, need_trans=False):
|
10 |
if need_trans:
|
11 |
txt = en2cn(txt)
|
12 |
+
types = txt_2_list(types_txt)
|
13 |
if radio == '文本分类':
|
14 |
result = text_classification(txt, types)
|
15 |
if radio == '实体抽取':
|
|
|
24 |
radio = gr.Radio(["文本分类", "实体抽取"], label="算法类型")
|
25 |
checkbox = gr.Checkbox(label="翻译成中文")
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
demo = gr.Interface(fn=auto_anno, inputs=[input1, input2, radio, checkbox], outputs=[output])
|
29 |
demo.launch(share=False)
|