shibing624 commited on
Commit
81465e6
·
1 Parent(s): 394b3b3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @author:XuMing([email protected])
4
+ @description: pip install gradio
5
+ """
6
+
7
+ import gradio as gr
8
+ from nerpy import NERModel
9
+
10
+ # 中文实体识别模型(BertSoftmax)
11
+ ner_model = NERModel(model_type='bert', model_name='shibing624/bert4ner-base-chinese')
12
+
13
+
14
+ def ai_text(sentence):
15
+ predictions, raw_outputs, entities = ner_model.predict([sentence])
16
+ print("{} \t Entity: {}".format(sentence, entities))
17
+
18
+ return entities
19
+
20
+
21
+ if __name__ == '__main__':
22
+ examples = [
23
+ ['常建良,男,1963年出生,工科学士,高级工程师,北京物资学院客座副教授'],
24
+ ['在国家物资局、物资部、国内贸易部金属材料流通司从事调拨分配工作'],
25
+ ]
26
+ input = gr.inputs.Textbox(lines=4, placeholder="Enter Sentence")
27
+
28
+ output_text = gr.outputs.Textbox()
29
+ gr.Interface(ai_text,
30
+ inputs=[input],
31
+ outputs=[output_text],
32
+ theme="grass",
33
+ title="Chinese Text to Vector Model shibing624/bert4ner-base-chinese",
34
+ description="Copy or input Chinese text here. Submit and the machine will calculate the NER entity.",
35
+ article="Link to <a href='https://github.com/shibing624/nerpy' style='color:blue;' target='_blank\'>Github REPO</a>",
36
+ examples=examples
37
+ ).launch()