carisackc commited on
Commit
a262720
1 Parent(s): cf57d05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +133 -22
app.py CHANGED
@@ -1,28 +1,139 @@
1
  import streamlit as st
 
 
 
 
 
 
 
 
2
 
3
- st.set_page_config(
4
- page_title="Hello",
5
- page_icon="👋",
6
- )
7
-
8
- st.write("# Welcome to Streamlit! 👋")
9
 
10
- st.sidebar.success("Select a demo above.")
 
11
 
 
 
 
 
12
  st.markdown(
13
  """
14
- Streamlit is an open-source app framework built specifically for
15
- Machine Learning and Data Science projects.
16
- **👈 Select a demo from the sidebar** to see some examples
17
- of what Streamlit can do!
18
- ### Want to learn more?
19
- - Check out [streamlit.io](https://streamlit.io)
20
- - Jump into our [documentation](https://docs.streamlit.io)
21
- - Ask a question in our [community
22
- forums](https://discuss.streamlit.io)
23
- ### See more complex demos
24
- - Use a neural net to [analyze the Udacity Self-driving Car Image
25
- Dataset](https://github.com/streamlit/demo-self-driving)
26
- - Explore a [New York City rideshare dataset](https://github.com/streamlit/demo-uber-nyc-pickups)
27
- """
28
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Store the initial value of widgets in session state
12
+ if "visibility" not in st.session_state:
13
+ st.session_state.visibility = "visible"
14
+ st.session_state.disabled = False
 
 
15
 
16
+ #nlp = en_core_web_lg.load()
17
+ nlp = spacy.load("en_ner_bc5cdr_md")
18
 
19
+ st.set_page_config(page_title ='Clinical Note Summarization',
20
+ #page_icon= "Notes",
21
+ layout='wide')
22
+ st.title('Clinical Note Summarization')
23
  st.markdown(
24
  """
25
+ <style>
26
+ [data-testid="stSidebar"][aria-expanded="true"] > div:first-child {
27
+ width: 400px;
28
+ }
29
+ [data-testid="stSidebar"][aria-expanded="false"] > div:first-child {
30
+ width: 400px;
31
+ margin-left: -230px;
32
+ }
33
+ </style>
34
+ """,
35
+ unsafe_allow_html=True,
36
+ )
37
+ st.sidebar.markdown('Using transformer model')
38
+
39
+ ## Loading in dataset
40
+ #df = pd.read_csv('mtsamples_small.csv',index_col=0)
41
+ df = pd.read_csv('shpi_w_rouge21Nov.csv')
42
+ df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
43
+
44
+ #Renaming column
45
+ df.rename(columns={'SUBJECT_ID':'Patient_ID',
46
+ 'HADM_ID':'Admission_ID',
47
+ 'hpi_input_text':'Original_Text',
48
+ 'hpi_reference_summary':'Reference_text'}, inplace = True)
49
+
50
+ #data.rename(columns={'gdp':'log(gdp)'}, inplace=True)
51
+
52
+ #Filter selection
53
+ st.sidebar.header("Search for Patient:")
54
+
55
+ patientid = df['Patient_ID']
56
+ patient = st.sidebar.selectbox('Select Patient ID:', patientid)
57
+ admissionid = df['Admission_ID'].loc[df['Patient_ID'] == patient]
58
+ HospitalAdmission = st.sidebar.selectbox('', admissionid)
59
+
60
+ # List of Model available
61
+ model = st.sidebar.selectbox('Select Model', ('BertSummarizer','BertGPT2','t5seq2eq','t5','gensim','pysummarizer'))
62
+
63
+ col3,col4 = st.columns(2)
64
+ patientid = col3.write(f"Patient ID: {patient} ")
65
+ admissionid =col4.write(f"Admission ID: {HospitalAdmission} ")
66
+
67
+
68
+ ##========= Buttons to the 4 tabs ========
69
+ col1, col2, col3, col4 = st.columns(4)
70
+ with col1:
71
+ # st.button('Admission')
72
+ st.button("🏥 Admission")
73
+ with col2:
74
+ st.button('📆Daily Narrative')
75
+ with col3:
76
+ st.button('Discharge Plan')
77
+ with col4:
78
+ st.button('📝Social Notes')
79
+
80
+
81
+ # Query out relevant Clinical notes
82
+ original_text = df.query(
83
+ "Patient_ID == @patient & Admission_ID == @HospitalAdmission"
84
+ )
85
+
86
+ original_text2 = original_text['Original_Text'].values
87
+
88
+ runtext =st.text_area('Input Clinical Note here:', str(original_text2), height=300)
89
+
90
+ reference_text = original_text['Reference_text'].values
91
+
92
+ def run_model(input_text):
93
+
94
+ if model == "BertSummarizer":
95
+ output = original_text['BertSummarizer'].values
96
+ st.write('Summary')
97
+ st.success(output[0])
98
+
99
+ elif model == "BertGPT2":
100
+ output = original_text['BertGPT2'].values
101
+ st.write('Summary')
102
+ st.success(output[0])
103
+
104
+
105
+ elif model == "t5seq2eq":
106
+ output = original_text['t5seq2eq'].values
107
+ st.write('Summary')
108
+ st.success(output)
109
+
110
+ elif model == "t5":
111
+ output = original_text['t5'].values
112
+ st.write('Summary')
113
+ st.success(output)
114
+
115
+ elif model == "gensim":
116
+ output = original_text['gensim'].values
117
+ st.write('Summary')
118
+ st.success(output)
119
+
120
+ elif model == "pysummarizer":
121
+ output = original_text['pysummarizer'].values
122
+ st.write('Summary')
123
+ st.success(output)
124
+
125
+ col1, col2 = st.columns([1,1])
126
+
127
+ with col1:
128
+ st.button('Summarize')
129
+ run_model(runtext)
130
+ sentences=runtext.split('.')
131
+ st.text_area('Reference text', str(reference_text))#,label_visibility="hidden")
132
+ with col2:
133
+ st.button('NER')
134
+ doc = nlp(str(original_text2))
135
+ colors = { "DISEASE": "pink","CHEMICAL": "orange"}
136
+ options = {"ents": [ "DISEASE", "CHEMICAL"],"colors": colors}
137
+ ent_html = displacy.render(doc, style="ent", options=options)
138
+ st.markdown(ent_html, unsafe_allow_html=True)
139
+