Spaces:
Build error
Build error
Upload 2 files
Browse files- Summarization_Simple_25Nov.py +115 -0
- demo_shpi_w_rouge25Nov.csv +0 -0
Summarization_Simple_25Nov.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 8 |
+
#nlp = en_core_web_lg.load()
|
| 9 |
+
|
| 10 |
+
st.set_page_config(layout='wide')
|
| 11 |
+
st.title('Clinical Note Summarization')
|
| 12 |
+
st.sidebar.markdown('Using transformer model')
|
| 13 |
+
|
| 14 |
+
## Loading in dataset
|
| 15 |
+
#df = pd.read_csv('mtsamples_small.csv',index_col=0)
|
| 16 |
+
df = pd.read_csv('shpi_w_rouge21Nov.csv')
|
| 17 |
+
df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))
|
| 18 |
+
|
| 19 |
+
#Renaming column
|
| 20 |
+
df.rename(columns={'SUBJECT_ID':'Patient_ID',
|
| 21 |
+
'HADM_ID':'Admission_ID',
|
| 22 |
+
'hpi_input_text':'Original_Text',
|
| 23 |
+
'hpi_reference_summary':'Reference_text'}, inplace = True)
|
| 24 |
+
|
| 25 |
+
#data.rename(columns={'gdp':'log(gdp)'}, inplace=True)
|
| 26 |
+
|
| 27 |
+
#Filter selection
|
| 28 |
+
st.sidebar.header("Search for Patient:")
|
| 29 |
+
|
| 30 |
+
patientid = df['Patient_ID']
|
| 31 |
+
patient = st.sidebar.selectbox('Select Patient ID:', patientid)
|
| 32 |
+
admissionid = df['Admission_ID'].loc[df['Patient_ID'] == patient]
|
| 33 |
+
HospitalAdmission = st.sidebar.selectbox('', admissionid)
|
| 34 |
+
|
| 35 |
+
# List of Model available
|
| 36 |
+
model = st.sidebar.selectbox('Select Model', ('BertSummarizer','BertGPT2','t5seq2eq','t5','gensim','pysummarizer'))
|
| 37 |
+
|
| 38 |
+
col3,col4 = st.columns(2)
|
| 39 |
+
patientid = col3.write(f"Patient ID: {patient} ")
|
| 40 |
+
admissionid =col4.write(f"Admission ID: {HospitalAdmission} ")
|
| 41 |
+
|
| 42 |
+
#text = st.text_area('Input Clinical Note here')
|
| 43 |
+
|
| 44 |
+
# Query out relevant Clinical notes
|
| 45 |
+
original_text = df.query(
|
| 46 |
+
"Patient_ID == @patient & Admission_ID == @HospitalAdmission"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
original_text2 = original_text['Original_Text'].values
|
| 50 |
+
|
| 51 |
+
runtext =st.text_area('Input Clinical Note here:', str(original_text2), height=300)
|
| 52 |
+
|
| 53 |
+
reference_text = original_text['Reference_text'].values
|
| 54 |
+
|
| 55 |
+
def run_model(input_text):
|
| 56 |
+
|
| 57 |
+
if model == "BertSummarizer":
|
| 58 |
+
output = original_text['BertSummarizer'].values
|
| 59 |
+
st.write('Summary')
|
| 60 |
+
st.success(output[0])
|
| 61 |
+
|
| 62 |
+
elif model == "BertGPT2":
|
| 63 |
+
output = original_text['BertGPT2'].values
|
| 64 |
+
st.write('Summary')
|
| 65 |
+
st.success(output[0])
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
elif model == "t5seq2eq":
|
| 69 |
+
output = original_text['t5seq2eq'].values
|
| 70 |
+
st.write('Summary')
|
| 71 |
+
st.success(output)
|
| 72 |
+
|
| 73 |
+
elif model == "t5":
|
| 74 |
+
output = original_text['t5'].values
|
| 75 |
+
st.write('Summary')
|
| 76 |
+
st.success(output)
|
| 77 |
+
|
| 78 |
+
elif model == "gensim":
|
| 79 |
+
output = original_text['gensim'].values
|
| 80 |
+
st.write('Summary')
|
| 81 |
+
st.success(output)
|
| 82 |
+
|
| 83 |
+
elif model == "pysummarizer":
|
| 84 |
+
output = original_text['pysummarizer'].values
|
| 85 |
+
st.write('Summary')
|
| 86 |
+
st.success(output)
|
| 87 |
+
|
| 88 |
+
if st.button('Submit'):
|
| 89 |
+
run_model(runtext)
|
| 90 |
+
|
| 91 |
+
sentences=runtext.split('.')
|
| 92 |
+
def visualize(title, sentence_list, best_sentences):
|
| 93 |
+
text = ''
|
| 94 |
+
|
| 95 |
+
#display(HTML(f'<h1>Summary - {title}</h1>'))
|
| 96 |
+
for sentence in sentence_list:
|
| 97 |
+
if sentence in best_sentences:
|
| 98 |
+
#text += ' ' + str(sentence).replace(sentence, f"<mark>{sentence}</mark>")
|
| 99 |
+
text += ' ' + str(sentence).replace(sentence, f"<span class='highlight yellow'>{sentence}</span>")
|
| 100 |
+
else:
|
| 101 |
+
text += ' ' + sentence
|
| 102 |
+
display(HTML(f""" {text} """))
|
| 103 |
+
|
| 104 |
+
output = ''
|
| 105 |
+
best_sentences = []
|
| 106 |
+
for sentence in output:
|
| 107 |
+
#print(sentence)
|
| 108 |
+
best_sentences.append(str(sentence))
|
| 109 |
+
return text
|
| 110 |
+
|
| 111 |
+
t = "<div>Hello there my <span class='highlight blue'>name <span class='bold'>yo</span> </span> is <span class='highlight red'>Fanilo <span class='bold'>Name</span></span></div>"
|
| 112 |
+
|
| 113 |
+
st.write("<div>Hello there my <span class='highlight blue'>name <span class='bold'>yo</span> </span> is <span class='highlight red'>Fanilo <span class='bold'>Name</span></span></div>")
|
| 114 |
+
|
| 115 |
+
st.text_area('Reference text', str(reference_text))
|
demo_shpi_w_rouge25Nov.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|