hanbinChen commited on
Commit
04a8bf0
·
1 Parent(s): 93411f7
Files changed (3) hide show
  1. README.md +8 -0
  2. app.py +44 -2
  3. mockData.json +138 -0
README.md CHANGED
@@ -10,3 +10,11 @@ pinned: false
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
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。
app.py CHANGED
@@ -1,4 +1,46 @@
1
  import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
7
+ entities = [
8
+ Selection(start=0, end=12, text="FINAL REPORT",
9
+ labels=["REPORT_TYPE"]),
10
+ Selection(start=22, end=33, text="Pseudomonas", labels=["DISEASE"]),
11
+ Selection(start=39, end=49, text="intubation", labels=["PROCEDURE"]),
12
+ Selection(start=62, end=67, text="study", labels=["EXAM"]),
13
+ Selection(start=116, end=126, text="Substantial", labels=["SEVERITY"]),
14
+ Selection(start=127, end=145, text="bilateral pleural",
15
+ labels=["ANATOMY"]),
16
+ Selection(start=146, end=155, text="effusions", labels=["OBSERVATION"])
17
+ ]
18
+ return entities
19
+
20
+
21
+ def main():
22
+ st.title("Medical Text Entity Recognition")
23
+
24
+ # 1. Text input
25
+ text = st.text_area("Enter medical text:", value="FINAL REPORT HISTORY : Pseudomonas with intubation . FINDINGS : In comparison with the study of ___ , there is little change in the monitoring and support devices . Substantial bilateral pleural effusions , more prominent on the right with bibasilar atelectasis .")
26
+
27
+ if st.button("Recognize Entities"):
28
+ # 2. Call the simulated entity recognition function
29
+ entities = mock_entity_recognition(text)
30
+
31
+ # 3. Use streamlit_text_label to highlight recognized entities
32
+ st.subheader("Recognition Results:")
33
+ labeled_text = label_select(
34
+ body=text,
35
+ labels=["REPORT_TYPE", "DISEASE", "PROCEDURE",
36
+ "EXAM", "SEVERITY", "ANATOMY", "OBSERVATION"],
37
+ selections=entities
38
+ )
39
+
40
+ st.write("Recognized entities:")
41
+ for entity in entities:
42
+ st.write(f"{entity.text} ({entity.labels[0]})")
43
+
44
+
45
+ if __name__ == "__main__":
46
+ main()
mockData.json ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {'data_source': 'MIMIC-CXR',
2
+ 'data_split': 'train',
3
+ 'entities': {'1': {'end_ix': 29,
4
+ 'label': 'OBS-DP',
5
+ 'relations': [['modify', '4']],
6
+ 'start_ix': 29,
7
+ 'tokens': 'Substantial'},
8
+ '10': {'end_ix': 44,
9
+ 'label': 'OBS-DP',
10
+ 'relations': [['suggestive_of', '16']],
11
+ 'start_ix': 44,
12
+ 'tokens': 'configuration'},
13
+ '11': {'end_ix': 47,
14
+ 'label': 'OBS-DP',
15
+ 'relations': [['modify', '12']],
16
+ 'start_ix': 47,
17
+ 'tokens': 'collection'},
18
+ '12': {'end_ix': 49,
19
+ 'label': 'OBS-DP',
20
+ 'relations': [['located_at', '14'],
21
+ ['suggestive_of', '16']],
22
+ 'start_ix': 49,
23
+ 'tokens': 'opacification'},
24
+ '13': {'end_ix': 52,
25
+ 'label': 'ANAT-DP',
26
+ 'relations': [['modify', '14']],
27
+ 'start_ix': 52,
28
+ 'tokens': 'left'},
29
+ '14': {'end_ix': 53,
30
+ 'label': 'ANAT-DP',
31
+ 'relations': [],
32
+ 'start_ix': 53,
33
+ 'tokens': 'base'},
34
+ '15': {'end_ix': 59,
35
+ 'label': 'OBS-U',
36
+ 'relations': [['modify', '16']],
37
+ 'start_ix': 59,
38
+ 'tokens': 'loculated'},
39
+ '16': {'end_ix': 60,
40
+ 'label': 'OBS-U',
41
+ 'relations': [],
42
+ 'start_ix': 60,
43
+ 'tokens': 'fluid'},
44
+ '17': {'end_ix': 67,
45
+ 'label': 'OBS-DP',
46
+ 'relations': [['modify', '20']],
47
+ 'start_ix': 67,
48
+ 'tokens': 'increased'},
49
+ '18': {'end_ix': 68,
50
+ 'label': 'ANAT-DP',
51
+ 'relations': [['modify', '19']],
52
+ 'start_ix': 68,
53
+ 'tokens': 'pulmonary'},
54
+ '19': {'end_ix': 69,
55
+ 'label': 'ANAT-DP',
56
+ 'relations': [],
57
+ 'start_ix': 69,
58
+ 'tokens': 'venous'},
59
+ '2': {'end_ix': 30,
60
+ 'label': 'ANAT-DP',
61
+ 'relations': [['modify', '3']],
62
+ 'start_ix': 30,
63
+ 'tokens': 'bilateral'},
64
+ '20': {'end_ix': 70,
65
+ 'label': 'OBS-DP',
66
+ 'relations': [['located_at', '19']],
67
+ 'start_ix': 70,
68
+ 'tokens': 'pressure'},
69
+ '21': {'end_ix': 79,
70
+ 'label': 'ANAT-DP',
71
+ 'relations': [['modify', '23']],
72
+ 'start_ix': 79,
73
+ 'tokens': 'left'},
74
+ '22': {'end_ix': 80,
75
+ 'label': 'ANAT-DP',
76
+ 'relations': [['modify', '23']],
77
+ 'start_ix': 80,
78
+ 'tokens': 'upper'},
79
+ '23': {'end_ix': 81,
80
+ 'label': 'ANAT-DP',
81
+ 'relations': [],
82
+ 'start_ix': 81,
83
+ 'tokens': 'zone'},
84
+ '24': {'end_ix': 87,
85
+ 'label': 'ANAT-DP',
86
+ 'relations': [],
87
+ 'start_ix': 87,
88
+ 'tokens': 'cavitary'},
89
+ '25': {'end_ix': 88,
90
+ 'label': 'OBS-DP',
91
+ 'relations': [['located_at', '24']],
92
+ 'start_ix': 88,
93
+ 'tokens': 'process'},
94
+ '3': {'end_ix': 31,
95
+ 'label': 'ANAT-DP',
96
+ 'relations': [],
97
+ 'start_ix': 31,
98
+ 'tokens': 'pleural'},
99
+ '4': {'end_ix': 32,
100
+ 'label': 'OBS-DP',
101
+ 'relations': [['located_at', '3']],
102
+ 'start_ix': 32,
103
+ 'tokens': 'effusions'},
104
+ '5': {'end_ix': 35,
105
+ 'label': 'OBS-DP',
106
+ 'relations': [['located_at', '6']],
107
+ 'start_ix': 35,
108
+ 'tokens': 'prominent'},
109
+ '6': {'end_ix': 38,
110
+ 'label': 'ANAT-DP',
111
+ 'relations': [['modify', '3']],
112
+ 'start_ix': 38,
113
+ 'tokens': 'right'},
114
+ '7': {'end_ix': 40,
115
+ 'label': 'ANAT-DP',
116
+ 'relations': [],
117
+ 'start_ix': 40,
118
+ 'tokens': 'bibasilar'},
119
+ '8': {'end_ix': 41,
120
+ 'label': 'OBS-DP',
121
+ 'relations': [['located_at', '6'], ['located_at', '7']],
122
+ 'start_ix': 41,
123
+ 'tokens': 'atelectasis'},
124
+ '9': {'end_ix': 43,
125
+ 'label': 'OBS-DP',
126
+ 'relations': [['modify', '10']],
127
+ 'start_ix': 43,
128
+ 'tokens': 'Unusual'}},
129
+ 'text': 'FINAL REPORT HISTORY : Pseudomonas with intubation . FINDINGS : In '
130
+ 'comparison with the study of ___ , there is little change in the '
131
+ 'monitoring and support devices . Substantial bilateral pleural '
132
+ 'effusions , more prominent on the right with bibasilar atelectasis . '
133
+ 'Unusual configuration to the collection of opacification at the left '
134
+ 'base raises the possibility of some loculated fluid . There is again '
135
+ 'evidence of increased pulmonary venous pressure . Overlapping '
136
+ 'structures somewhat obscure visualization of the left upper zone and '
137
+ 'simulate the appearance of cavitary process . This area should be '
138
+ 'closely checked on subsequent radiographs .'}