carisackc commited on
Commit
e095f32
·
1 Parent(s): 06ff6d2

Delete pages/2_Daily Narrative.py

Browse files
Files changed (1) hide show
  1. pages/2_Daily Narrative.py +0 -174
pages/2_Daily Narrative.py DELETED
@@ -1,174 +0,0 @@
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
- from streamlit.components.v1 import html
12
-
13
- def nav_page(page_name, timeout_secs=3):
14
- nav_script = """
15
- <script type="text/javascript">
16
- function attempt_nav_page(page_name, start_time, timeout_secs) {
17
- var links = window.parent.document.getElementsByTagName("a");
18
- for (var i = 0; i < links.length; i++) {
19
- if (links[i].href.toLowerCase().endsWith("/" + page_name.toLowerCase())) {
20
- links[i].click();
21
- return;
22
- }
23
- }
24
- var elasped = new Date() - start_time;
25
- if (elasped < timeout_secs * 1000) {
26
- setTimeout(attempt_nav_page, 100, page_name, start_time, timeout_secs);
27
- } else {
28
- alert("Unable to navigate to page '" + page_name + "' after " + timeout_secs + " second(s).");
29
- }
30
- }
31
- window.addEventListener("load", function() {
32
- attempt_nav_page("%s", new Date(), %d);
33
- });
34
- </script>
35
- """ % (page_name, timeout_secs)
36
- html(nav_script)
37
-
38
-
39
- # Store the initial value of widgets in session state
40
- if "visibility" not in st.session_state:
41
- st.session_state.visibility = "visible"
42
- st.session_state.disabled = False
43
-
44
- #nlp = en_core_web_lg.load()
45
- nlp = spacy.load("en_ner_bc5cdr_md")
46
-
47
- st.set_page_config(page_title ='📆 Daily Narrative',
48
- layout='wide')
49
-
50
- st.title('Clinical Note Summarization - Daily Narrative')
51
- st.markdown(
52
- """
53
- <style>
54
- [data-testid="stSidebar"][aria-expanded="true"] > div:first-child {
55
- width: 400px;
56
- }
57
- [data-testid="stSidebar"][aria-expanded="false"] > div:first-child {
58
- width: 400px;
59
- margin-left: -230px;
60
- }
61
- </style>
62
- """,
63
- unsafe_allow_html=True,
64
- )
65
- st.sidebar.markdown('Using transformer model')
66
-
67
- ## Loading in dataset
68
- #df = pd.read_csv('mtsamples_small.csv',index_col=0)
69
- df = pd.read_csv('shpi_w_rouge21Nov.csv')
70
- df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
71
-
72
- #Renaming column
73
- df.rename(columns={'SUBJECT_ID':'Patient_ID',
74
- 'HADM_ID':'Admission_ID',
75
- 'hpi_input_text':'Original_Text',
76
- 'hpi_reference_summary':'Reference_text'}, inplace = True)
77
-
78
- #data.rename(columns={'gdp':'log(gdp)'}, inplace=True)
79
-
80
- #Filter selection
81
- st.sidebar.header("Search for Patient:")
82
-
83
- patientid = df['Patient_ID']
84
- patient = st.sidebar.selectbox('Select Patient ID:', patientid)
85
- admissionid = df['Admission_ID'].loc[df['Patient_ID'] == patient]
86
- HospitalAdmission = st.sidebar.selectbox('', admissionid)
87
-
88
- # List of Model available
89
- model = st.sidebar.selectbox('Select Model', ('BertSummarizer','BertGPT2','t5seq2eq','t5','gensim','pysummarizer'))
90
-
91
- col3,col4 = st.columns(2)
92
- patientid = col3.write(f"Patient ID: {patient} ")
93
- admissionid =col4.write(f"Admission ID: {HospitalAdmission} ")
94
-
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
-