hanbinChen commited on
Commit
e81f16d
·
1 Parent(s): 1b1752f
Files changed (3) hide show
  1. README.md +35 -7
  2. app.py +45 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -9,12 +9,40 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
 
 
14
 
15
- 用streamlit做一个网站。
16
- 1. 输入是文本。
17
- 1. 先用mockData.json的text测试。
18
- 2. 功能是进行调用api对文本进行实体识别,得到list of entity。
19
- 1. 先mock这个功能。输出mockData.json的entities。
20
- 3. 一个输出模块,使用streamlit_text_label,高亮文本中的list of entity。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ # Medical Knowledge Graph Construction (medKGC)
13
 
14
+ ## English Version
15
 
16
+ medKGC is a Streamlit-based application for medical text analysis and knowledge graph construction. It demonstrates the process of entity recognition and relation extraction from medical texts, visualizing the results in an interactive graph.
17
+
18
+ ### Features:
19
+ 1. Text Input: Users can input medical text for analysis.
20
+ 2. Entity Recognition: The app identifies and highlights various medical entities such as diseases, procedures, anatomy, etc.
21
+ 3. Relation Extraction: It extracts relationships between the identified entities.
22
+ 4. Interactive Visualization: Utilizes streamlit-agraph to create an interactive graph representation of entities and their relationships.
23
+ 5. Labeled Text Display: Shows the input text with highlighted entities using streamlit_text_label.
24
+
25
+ ### How to Use:
26
+ 1. Enter medical text in the provided text area.
27
+ 2. Click "Recognize Entities" to process the text.
28
+ 3. View the recognized entities, extracted relations, and the entity relationship graph.
29
+
30
+ Note: Currently, the app uses mock data for demonstration purposes. Integration with actual NLP models is planned for future development.
31
+
32
+ ## 中文版本
33
+
34
+ medKGC 是一个基于 Streamlit 的医疗文本分析和知识图谱构建应用。它演示了从医疗文本中进行实体识别和关系提取的过程,并将结果以交互式图形可视化。
35
+
36
+ ### 功能特点:
37
+ 1. 文本输入:用户可以输入医疗文本进行分析。
38
+ 2. 实体识别:应用程序识别并高亮显示各种医疗实体,如疾病、医疗程序、解剖结构等。
39
+ 3. 关系提取:提取识别出的实体之间的关系。
40
+ 4. 交互式可视化:使用 streamlit-agraph 创建实体及其关系的交互式图形表示。
41
+ 5. 标记文本显示:使用 streamlit_text_label 显示带有高亮实体的输入文本。
42
+
43
+ ### 使用方法:
44
+ 1. 在提供的文本区域输入医疗文本。
45
+ 2. 点击"识别实体"按钮处理文本。
46
+ 3. 查看识别出的实体、提取的关系以及实体关系图。
47
+
48
+ 注意:目前,应用程序使用模拟数据进行演示。未来开发计划将集成实际的自然语言处理模型。
app.py CHANGED
@@ -1,6 +1,15 @@
1
  import streamlit as st
2
  from streamlit_text_label import label_select, Selection
 
3
 
 
 
 
 
 
 
 
 
4
 
5
  def mock_entity_recognition(text):
6
  # Simulate entity recognition functionality
@@ -18,6 +27,31 @@ def mock_entity_recognition(text):
18
  return entities
19
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def main():
22
  st.title("Medical Text Entity Recognition")
23
 
@@ -41,6 +75,17 @@ def main():
41
  for entity in entities:
42
  st.write(f"{entity.text} ({entity.labels[0]})")
43
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  if __name__ == "__main__":
46
  main()
 
1
  import streamlit as st
2
  from streamlit_text_label import label_select, Selection
3
+ from streamlit_agraph import agraph, Node, Edge, Config
4
 
5
+ # Import Relation class
6
+ from dataclasses import dataclass
7
+
8
+ @dataclass
9
+ class Relation:
10
+ source: Selection
11
+ target: Selection
12
+ label: str
13
 
14
  def mock_entity_recognition(text):
15
  # Simulate entity recognition functionality
 
27
  return entities
28
 
29
 
30
+ def mock_relation_extraction(entities):
31
+ # Simulate relation extraction functionality
32
+ relations = [
33
+ Relation(source=entities[0],
34
+ target=entities[1], label="DISEASE_CAUSE"),
35
+ Relation(source=entities[1], target=entities[2],
36
+ label="PROCEDURE_EFFECT"),
37
+ Relation(source=entities[2], target=entities[3], label="EXAM_RESULT"),
38
+ Relation(source=entities[3], target=entities[4],
39
+ label="SEVERITY_LEVEL"),
40
+ Relation(source=entities[4], target=entities[5],
41
+ label="ANATOMY_LOCATION"),
42
+ ]
43
+
44
+ return relations
45
+
46
+
47
+ def create_graph(entities, relations):
48
+ nodes = [Node(id=e.text, label=e.text, size=25, color=f"#{hash(e.labels[0]) % 0xFFFFFF:06x}") for e in entities]
49
+ edges = [Edge(source=r.source.text, target=r.target.text, label=r.label) for r in relations]
50
+
51
+ config = Config(width=750, height=500, directed=True, physics=True, hierarchical=False)
52
+ return agraph(nodes=nodes, edges=edges, config=config)
53
+
54
+
55
  def main():
56
  st.title("Medical Text Entity Recognition")
57
 
 
75
  for entity in entities:
76
  st.write(f"{entity.text} ({entity.labels[0]})")
77
 
78
+ # 4. Call the simulated relation extraction function
79
+ relations = mock_relation_extraction(entities)
80
+
81
+ # 5. Display relations
82
+ st.subheader("Extracted Relations:")
83
+ for relation in relations:
84
+ st.write(f"{relation.source.text} --{relation.label}--> {relation.target.text}")
85
+
86
+ # 6. Create and display graph using streamlit-agraph
87
+ st.subheader("Entity Relationship Graph:")
88
+ create_graph(entities, relations)
89
 
90
  if __name__ == "__main__":
91
  main()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  streamlit
2
  streamlit_text_label
 
 
1
  streamlit
2
  streamlit_text_label
3
+ streamlit-agraph