Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,8 +44,15 @@ st.sidebar.markdown('Using transformer model')
|
|
| 44 |
## Loading in dataset
|
| 45 |
#df = pd.read_csv('mtsamples_small.csv',index_col=0)
|
| 46 |
df = pd.read_csv('shpi_w_rouge21Nov.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 48 |
|
|
|
|
| 49 |
#Renaming column
|
| 50 |
df.rename(columns={'SUBJECT_ID':'Patient_ID',
|
| 51 |
'HADM_ID':'Admission_ID',
|
|
@@ -60,7 +67,7 @@ st.sidebar.header("Search for Patient:")
|
|
| 60 |
patientid = df['Patient_ID']
|
| 61 |
patient = st.sidebar.selectbox('Select Patient ID:', patientid)
|
| 62 |
admissionid = df['Admission_ID'].loc[df['Patient_ID'] == patient]
|
| 63 |
-
HospitalAdmission = st.sidebar.selectbox('', admissionid)
|
| 64 |
|
| 65 |
# List of Model available
|
| 66 |
model = st.sidebar.selectbox('Select Model', ('BertSummarizer','BertGPT2','t5seq2eq','t5','gensim','pysummarizer'))
|
|
@@ -75,31 +82,47 @@ original_text = df.query(
|
|
| 75 |
"Patient_ID == @patient & Admission_ID == @HospitalAdmission"
|
| 76 |
)
|
| 77 |
original_text2 = original_text['Original_Text'].values
|
|
|
|
|
|
|
| 78 |
reference_text = original_text['Reference_text'].values
|
| 79 |
|
| 80 |
-
##========= Buttons to the 4 tabs ========
|
| 81 |
-
col1, col2, col3, col4 = st.columns(4)
|
| 82 |
-
|
| 83 |
-
with col1:
|
| 84 |
-
if st.button("🏥 Admission"):
|
| 85 |
-
#nav_page('Admission')
|
| 86 |
-
inputNote = "Input Admission Note"
|
| 87 |
-
|
| 88 |
-
with col2:
|
| 89 |
-
if st.button('📆Daily Narrative'):
|
| 90 |
-
#nav_page('Daily Narrative')
|
| 91 |
-
inputNote = "Input Daily Narrative Note"
|
| 92 |
-
with col3:
|
| 93 |
-
if st.button('🗒️Discharge Plan'):
|
| 94 |
-
#nav_page('Discharge Plan')
|
| 95 |
-
inputNote = "Input Discharge Plan"
|
| 96 |
-
with col4:
|
| 97 |
-
if st.button('📝Social Notes'):
|
| 98 |
-
#nav_page('Social Notes')
|
| 99 |
-
inputNote = "Input Social Note"
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
runtext =st.text_area(inputNote, str(original_text2), height=300)
|
| 102 |
|
|
|
|
| 103 |
# Extract words associated with each entity
|
| 104 |
def genEntities(ann, entity):
|
| 105 |
# entity colour dict
|
|
@@ -112,27 +135,12 @@ def genEntities(ann, entity):
|
|
| 112 |
ent = list(trans_df[trans_df['Class']==entity]['Entity'].unique())
|
| 113 |
entlist = ",".join(ent)
|
| 114 |
st.markdown(f'<p style="background-color:{ent_col[entity]};color:#080808;font-size:16px;">{entlist}</p>', unsafe_allow_html=True)
|
| 115 |
-
|
| 116 |
-
#st.markdown(f'<p style="color:{ent_col[entity]};font-size:20px;">{i}</p>', unsafe_allow_html=True)
|
| 117 |
-
|
| 118 |
|
| 119 |
def visualize (run_text,output):
|
| 120 |
text =''
|
| 121 |
splitruntext = [x for x in runtext.split('.')]
|
| 122 |
splitoutput = [x for x in output.split('.')]
|
| 123 |
-
# best_sentences = []
|
| 124 |
-
# for sentence in output:
|
| 125 |
-
# best_sentences.append(str(sentence))
|
| 126 |
-
|
| 127 |
-
# text = ''
|
| 128 |
-
|
| 129 |
-
# #display(HTML(f'<h1>Summary - {title}</h1>'))
|
| 130 |
-
# for sentence in run_text:
|
| 131 |
-
# if sentence in best_sentences:
|
| 132 |
-
# text += ' ' + str(sentence).replace(sentence, f"<mark>{sentence}</mark>")
|
| 133 |
-
# else:
|
| 134 |
-
# text += ' ' + sentence
|
| 135 |
-
# display(HTML(f""" {text} """))
|
| 136 |
return splitoutput,splitruntext
|
| 137 |
|
| 138 |
|
|
@@ -162,19 +170,19 @@ def run_model(input_text):
|
|
| 162 |
output = original_text['pysummarizer'].values
|
| 163 |
st.write('Summary')
|
| 164 |
|
| 165 |
-
|
| 166 |
st.success(output)
|
| 167 |
-
|
| 168 |
doc = nlp(str(original_text2))
|
| 169 |
colors = { "DISEASE": "pink","CHEMICAL": "orange"}
|
| 170 |
options = {"ents": [ "DISEASE", "CHEMICAL"],"colors": colors}
|
| 171 |
ent_html = displacy.render(doc, style="ent", options=options)
|
| 172 |
|
| 173 |
-
col1, col2 = st.columns([1,
|
| 174 |
with col1:
|
| 175 |
st.button('Summarize')
|
| 176 |
run_model(runtext)
|
| 177 |
-
sentences=runtext.split('.')
|
| 178 |
st.text_area('Reference text', str(reference_text), height=150)
|
| 179 |
##====== Storing the Diseases/Text
|
| 180 |
table= {"Entity":[], "Class":[]}
|
|
@@ -188,13 +196,18 @@ with col1:
|
|
| 188 |
|
| 189 |
with col2:
|
| 190 |
st.button('NER')
|
| 191 |
-
st.markdown('**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
genEntities(trans_df, 'DISEASE')
|
| 193 |
-
st.markdown('**
|
| 194 |
genEntities(trans_df, 'CHEMICAL')
|
| 195 |
#st.table(trans_df)
|
| 196 |
st.markdown('**NER**')
|
| 197 |
st.markdown(ent_html, unsafe_allow_html=True)
|
|
|
|
| 198 |
|
| 199 |
|
| 200 |
|
|
|
|
| 44 |
## Loading in dataset
|
| 45 |
#df = pd.read_csv('mtsamples_small.csv',index_col=0)
|
| 46 |
df = pd.read_csv('shpi_w_rouge21Nov.csv')
|
| 47 |
+
#Loading in Admission chief Complaint and diagnosis
|
| 48 |
+
df2 = pd.read_csv('cohort_cc_adm_diag.csv')
|
| 49 |
+
|
| 50 |
+
#combining both data into one
|
| 51 |
+
df = pd.merge(df, df2, on=['HADM_ID','SUBJECT_ID'])
|
| 52 |
+
|
| 53 |
df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 54 |
|
| 55 |
+
|
| 56 |
#Renaming column
|
| 57 |
df.rename(columns={'SUBJECT_ID':'Patient_ID',
|
| 58 |
'HADM_ID':'Admission_ID',
|
|
|
|
| 67 |
patientid = df['Patient_ID']
|
| 68 |
patient = st.sidebar.selectbox('Select Patient ID:', patientid)
|
| 69 |
admissionid = df['Admission_ID'].loc[df['Patient_ID'] == patient]
|
| 70 |
+
HospitalAdmission = st.sidebar.selectbox(' ', admissionid)
|
| 71 |
|
| 72 |
# List of Model available
|
| 73 |
model = st.sidebar.selectbox('Select Model', ('BertSummarizer','BertGPT2','t5seq2eq','t5','gensim','pysummarizer'))
|
|
|
|
| 82 |
"Patient_ID == @patient & Admission_ID == @HospitalAdmission"
|
| 83 |
)
|
| 84 |
original_text2 = original_text['Original_Text'].values
|
| 85 |
+
AdmissionChiefCom = original_text['Admission_Chief_Complaint'].values
|
| 86 |
+
diagnosis =original_text['DIAGNOSIS'].values
|
| 87 |
reference_text = original_text['Reference_text'].values
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
##========= Buttons to the 4 tabs ========
|
| 91 |
+
col1, col2, col3, col4, col5 = st.columns([1,1,1,1,1])
|
| 92 |
+
col6, col7 =st.columns([2,2])
|
| 93 |
+
with st.container():
|
| 94 |
+
with col1:
|
| 95 |
+
btnAdmission = st.button("🏥 Admission")
|
| 96 |
+
if btnAdmission:
|
| 97 |
+
#nav_page('Admission')
|
| 98 |
+
inputNote = "Input Admission Note"
|
| 99 |
+
with col2:
|
| 100 |
+
btnDailyNarrative = st.button('📆Daily Narrative')
|
| 101 |
+
if btnDailyNarrative:
|
| 102 |
+
inputNote = "Input Daily Narrative Note"
|
| 103 |
+
with col3:
|
| 104 |
+
btnDischargePlan = st.button('🗒️Discharge Plan')
|
| 105 |
+
if btnDischargePlan:
|
| 106 |
+
inputNote = "Input Discharge Plan"
|
| 107 |
+
with col4:
|
| 108 |
+
btnSocialNotes = st.button('📝Social Notes')
|
| 109 |
+
if btnSocialNotes:
|
| 110 |
+
inputNote = "Input Social Note"
|
| 111 |
+
with col5:
|
| 112 |
+
btnPastHistory = st.button('📇Past History (6 Mths)')
|
| 113 |
+
if btnPastHistory:
|
| 114 |
+
inputNote = "Input History records"
|
| 115 |
+
|
| 116 |
+
with st.container():
|
| 117 |
+
if btnPastHistory:
|
| 118 |
+
with col6:
|
| 119 |
+
st.markdown('**No. of admission past 6 months: xx**')
|
| 120 |
+
with col7:
|
| 121 |
+
st.date_input('Select Admission Date')
|
| 122 |
+
|
| 123 |
runtext =st.text_area(inputNote, str(original_text2), height=300)
|
| 124 |
|
| 125 |
+
|
| 126 |
# Extract words associated with each entity
|
| 127 |
def genEntities(ann, entity):
|
| 128 |
# entity colour dict
|
|
|
|
| 135 |
ent = list(trans_df[trans_df['Class']==entity]['Entity'].unique())
|
| 136 |
entlist = ",".join(ent)
|
| 137 |
st.markdown(f'<p style="background-color:{ent_col[entity]};color:#080808;font-size:16px;">{entlist}</p>', unsafe_allow_html=True)
|
| 138 |
+
|
|
|
|
|
|
|
| 139 |
|
| 140 |
def visualize (run_text,output):
|
| 141 |
text =''
|
| 142 |
splitruntext = [x for x in runtext.split('.')]
|
| 143 |
splitoutput = [x for x in output.split('.')]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
return splitoutput,splitruntext
|
| 145 |
|
| 146 |
|
|
|
|
| 170 |
output = original_text['pysummarizer'].values
|
| 171 |
st.write('Summary')
|
| 172 |
|
| 173 |
+
|
| 174 |
st.success(output)
|
| 175 |
+
|
| 176 |
doc = nlp(str(original_text2))
|
| 177 |
colors = { "DISEASE": "pink","CHEMICAL": "orange"}
|
| 178 |
options = {"ents": [ "DISEASE", "CHEMICAL"],"colors": colors}
|
| 179 |
ent_html = displacy.render(doc, style="ent", options=options)
|
| 180 |
|
| 181 |
+
col1, col2 = st.columns([1,1])
|
| 182 |
with col1:
|
| 183 |
st.button('Summarize')
|
| 184 |
run_model(runtext)
|
| 185 |
+
#sentences=runtext.split('.')
|
| 186 |
st.text_area('Reference text', str(reference_text), height=150)
|
| 187 |
##====== Storing the Diseases/Text
|
| 188 |
table= {"Entity":[], "Class":[]}
|
|
|
|
| 196 |
|
| 197 |
with col2:
|
| 198 |
st.button('NER')
|
| 199 |
+
st.markdown('**CHIEF COMPLAINT:**')
|
| 200 |
+
st.write(str(AdmissionChiefCom))
|
| 201 |
+
st.markdown('**ADMISSION DIAGNOSIS:**')
|
| 202 |
+
st.markdown(str(diagnosis))
|
| 203 |
+
st.markdown('**PROBLEM/ISSUE**')
|
| 204 |
genEntities(trans_df, 'DISEASE')
|
| 205 |
+
st.markdown('**MEDICATION**')
|
| 206 |
genEntities(trans_df, 'CHEMICAL')
|
| 207 |
#st.table(trans_df)
|
| 208 |
st.markdown('**NER**')
|
| 209 |
st.markdown(ent_html, unsafe_allow_html=True)
|
| 210 |
+
|
| 211 |
|
| 212 |
|
| 213 |
|