lz-12 commited on
Commit
b29532c
·
verified ·
1 Parent(s): 42337f1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # 加载模型
5
+ print("正在加载病理检测NER模型...")
6
+ ner = pipeline(
7
+ "token-classification",
8
+ model="OpenMed/OpenMed-NER-PathologyDetect-BigMed-560M",
9
+ aggregation_strategy="max"
10
+ )
11
+ print("模型加载完成!")
12
+
13
+ # 处理函数
14
+ def process_text(text):
15
+ if not text:
16
+ return "请输入医学文本"
17
+
18
+ results = ner(text)
19
+ output = ""
20
+
21
+ for result in results:
22
+ entity = result["entity_group"]
23
+ word = result["word"]
24
+ score = round(result["score"], 2)
25
+ output += f"检测到病理实体: {word} (类型: {entity}, 置信度: {score})\n"
26
+
27
+ if not output:
28
+ output = "未检测到任何病理相关实体"
29
+
30
+ return output
31
+
32
+ # 创建界面
33
+ demo = gr.Interface(
34
+ fn=process_text,
35
+ inputs=gr.Textbox(placeholder="请输入医学文本...", lines=5),
36
+ outputs="text",
37
+ title="OpenMed 病理检测 NER 模型演示",
38
+ description="使用OpenMed-NER-PathologyDetect-BigMed-560M模型识别文本中的病理实体"
39
+ )
40
+
41
+ # 启动服务
42
+ demo.launch()