carisackc commited on
Commit
992a9a3
·
1 Parent(s): e095f32

Create pages/2_Daily Narrative

Browse files
Files changed (1) hide show
  1. pages/2_Daily Narrative +174 -0
pages/2_Daily Narrative ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from math import ceil
5
+ from collections import Counter
6
+ from string import punctuation
7
+ import spacy
8
+ from spacy import displacy
9
+ import en_ner_bc5cdr_md
10
+
11
+
12
+ from streamlit.components.v1 import html
13
+
14
+ def nav_page(page_name, timeout_secs=3):
15
+ nav_script = """
16
+ <script type="text/javascript">
17
+ function attempt_nav_page(page_name, start_time, timeout_secs) {
18
+ var links = window.parent.document.getElementsByTagName("a");
19
+ for (var i = 0; i < links.length; i++) {
20
+ if (links[i].href.toLowerCase().endsWith("/" + page_name.toLowerCase())) {
21
+ links[i].click();
22
+ return;
23
+ }
24
+ }
25
+ var elasped = new Date() - start_time;
26
+ if (elasped < timeout_secs * 1000) {
27
+ setTimeout(attempt_nav_page, 100, page_name, start_time, timeout_secs);
28
+ } else {
29
+ alert("Unable to navigate to page '" + page_name + "' after " + timeout_secs + " second(s).");
30
+ }
31
+ }
32
+ window.addEventListener("load", function() {
33
+ attempt_nav_page("%s", new Date(), %d);
34
+ });
35
+ </script>
36
+ """ % (page_name, timeout_secs)
37
+ html(nav_script)
38
+
39
+
40
+ # Store the initial value of widgets in session state
41
+ if "visibility" not in st.session_state:
42
+ st.session_state.visibility = "visible"
43
+ st.session_state.disabled = False
44
+
45
+ #nlp = en_core_web_lg.load()
46
+ nlp = spacy.load("en_ner_bc5cdr_md")
47
+
48
+ st.set_page_config(page_title ='📆Daily Narrative',
49
+ #page_icon= "Notes",
50
+ layout='wide')
51
+ st.title('Clinical Note Summarization - Admission')
52
+ st.markdown(
53
+ """
54
+ <style>
55
+ [data-testid="stSidebar"][aria-expanded="true"] > div:first-child {
56
+ width: 400px;
57
+ }
58
+ [data-testid="stSidebar"][aria-expanded="false"] > div:first-child {
59
+ width: 400px;
60
+ margin-left: -230px;
61
+ }
62
+ </style>
63
+ """,
64
+ unsafe_allow_html=True,
65
+ )
66
+ st.sidebar.markdown('Using transformer model')
67
+
68
+ ## Loading in dataset
69
+ #df = pd.read_csv('mtsamples_small.csv',index_col=0)
70
+ df = pd.read_csv('shpi_w_rouge21Nov.csv')
71
+ df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
72
+
73
+ #Renaming column
74
+ df.rename(columns={'SUBJECT_ID':'Patient_ID',
75
+ 'HADM_ID':'Admission_ID',
76
+ 'hpi_input_text':'Original_Text',
77
+ 'hpi_reference_summary':'Reference_text'}, inplace = True)
78
+
79
+ #data.rename(columns={'gdp':'log(gdp)'}, inplace=True)
80
+
81
+ #Filter selection
82
+ st.sidebar.header("Search for Patient:")
83
+
84
+ patientid = df['Patient_ID']
85
+ patient = st.sidebar.selectbox('Select Patient ID:', patientid)
86
+ admissionid = df['Admission_ID'].loc[df['Patient_ID'] == patient]
87
+ HospitalAdmission = st.sidebar.selectbox('', admissionid)
88
+
89
+ # List of Model available
90
+ model = st.sidebar.selectbox('Select Model', ('BertSummarizer','BertGPT2','t5seq2eq','t5','gensim','pysummarizer'))
91
+
92
+ col3,col4 = st.columns(2)
93
+ patientid = col3.write(f"Patient ID: {patient} ")
94
+ admissionid =col4.write(f"Admission ID: {HospitalAdmission} ")
95
+
96
+
97
+ ##========= Buttons to the 4 tabs ========
98
+ col1, col2, col3, col4 = st.columns(4)
99
+ with col1:
100
+ # st.button('Admission')
101
+ if st.button("🏥 Admission"):
102
+ nav_page('Admission')
103
+
104
+ with col2:
105
+ if st.button('📆Daily Narrative'):
106
+ nav_page('Daily Narrative')
107
+
108
+ with col3:
109
+ if st.button('Discharge Plan'):
110
+ nav_page('Discharge Plan')
111
+ with col4:
112
+ if st.button('📝Social Notes'):
113
+ nav_page('Social Notes')
114
+
115
+
116
+ # Query out relevant Clinical notes
117
+ original_text = df.query(
118
+ "Patient_ID == @patient & Admission_ID == @HospitalAdmission"
119
+ )
120
+
121
+ original_text2 = original_text['Original_Text'].values
122
+
123
+ runtext =st.text_area('Input Clinical Note here:', str(original_text2), height=300)
124
+
125
+ reference_text = original_text['Reference_text'].values
126
+
127
+ def run_model(input_text):
128
+
129
+ if model == "BertSummarizer":
130
+ output = original_text['BertSummarizer'].values
131
+ st.write('Summary')
132
+ st.success(output[0])
133
+
134
+ elif model == "BertGPT2":
135
+ output = original_text['BertGPT2'].values
136
+ st.write('Summary')
137
+ st.success(output[0])
138
+
139
+
140
+ elif model == "t5seq2eq":
141
+ output = original_text['t5seq2eq'].values
142
+ st.write('Summary')
143
+ st.success(output)
144
+
145
+ elif model == "t5":
146
+ output = original_text['t5'].values
147
+ st.write('Summary')
148
+ st.success(output)
149
+
150
+ elif model == "gensim":
151
+ output = original_text['gensim'].values
152
+ st.write('Summary')
153
+ st.success(output)
154
+
155
+ elif model == "pysummarizer":
156
+ output = original_text['pysummarizer'].values
157
+ st.write('Summary')
158
+ st.success(output)
159
+
160
+ col1, col2 = st.columns([1,1])
161
+
162
+ with col1:
163
+ st.button('Summarize')
164
+ run_model(runtext)
165
+ sentences=runtext.split('.')
166
+ st.text_area('Reference text', str(reference_text))#,label_visibility="hidden")
167
+ with col2:
168
+ st.button('NER')
169
+ doc = nlp(str(original_text2))
170
+ colors = { "DISEASE": "pink","CHEMICAL": "orange"}
171
+ options = {"ents": [ "DISEASE", "CHEMICAL"],"colors": colors}
172
+ ent_html = displacy.render(doc, style="ent", options=options)
173
+ st.markdown(ent_html, unsafe_allow_html=True)
174
+