File size: 3,767 Bytes
26357eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import streamlit as st
import pandas as pd
import numpy as np
from math import ceil
from collections import Counter
from string import punctuation

#nlp = en_core_web_lg.load()

st.set_page_config(layout='wide')
st.title('Clinical Note Summarization')
st.sidebar.markdown('Using transformer model')

## Loading in dataset
#df = pd.read_csv('mtsamples_small.csv',index_col=0)
df = pd.read_csv('shpi_w_rouge21Nov.csv')
df['HADM_ID'] = df['HADM_ID'].astype(str).apply(lambda x: x.replace('.0',''))

#Renaming column
df.rename(columns={'SUBJECT_ID':'Patient_ID',
                  'HADM_ID':'Admission_ID',
                  'hpi_input_text':'Original_Text',
                  'hpi_reference_summary':'Reference_text'}, inplace = True)
 
 #data.rename(columns={'gdp':'log(gdp)'}, inplace=True)

#Filter selection 
st.sidebar.header("Search for Patient:")

patientid = df['Patient_ID']
patient = st.sidebar.selectbox('Select Patient ID:', patientid)
admissionid = df['Admission_ID'].loc[df['Patient_ID'] == patient]
HospitalAdmission = st.sidebar.selectbox('', admissionid) 

# List of Model available
model = st.sidebar.selectbox('Select Model', ('BertSummarizer','BertGPT2','t5seq2eq','t5','gensim','pysummarizer'))

col3,col4 = st.columns(2) 
patientid = col3.write(f"Patient ID:  {patient} ")
admissionid =col4.write(f"Admission ID:  {HospitalAdmission} ")
   
#text = st.text_area('Input Clinical Note here')

# Query out relevant Clinical notes
original_text =  df.query(
    "Patient_ID  == @patient & Admission_ID == @HospitalAdmission"
)

original_text2 = original_text['Original_Text'].values

runtext =st.text_area('Input Clinical Note here:', str(original_text2), height=300)

reference_text = original_text['Reference_text'].values

def run_model(input_text):

    if model == "BertSummarizer":
        output = original_text['BertSummarizer'].values
        st.write('Summary')
        st.success(output[0])

    elif model == "BertGPT2":
        output = original_text['BertGPT2'].values
        st.write('Summary')
        st.success(output[0])
        
      
    elif model == "t5seq2eq": 
        output = original_text['t5seq2eq'].values
        st.write('Summary')
        st.success(output)
        
    elif model == "t5":
        output = original_text['t5'].values
        st.write('Summary')
        st.success(output)
        
    elif model == "gensim": 
        output = original_text['gensim'].values
        st.write('Summary')
        st.success(output)
        
    elif model == "pysummarizer": 
        output = original_text['pysummarizer'].values
        st.write('Summary')
        st.success(output)
        
if st.button('Submit'):
    run_model(runtext)
    
    sentences=runtext.split('.')
def visualize(title, sentence_list, best_sentences):
  text = ''

  #display(HTML(f'<h1>Summary - {title}</h1>'))
  for sentence in sentence_list:
    if sentence in best_sentences:
      #text += ' ' + str(sentence).replace(sentence, f"<mark>{sentence}</mark>")
      text += ' ' + str(sentence).replace(sentence, f"<span class='highlight yellow'>{sentence}</span>")
    else:
      text += ' ' + sentence
      display(HTML(f""" {text} """))

    output = ''   
    best_sentences = []
    for sentence in output:
       #print(sentence)
       best_sentences.append(str(sentence))
    return text     

    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>"

    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>")  
  
    st.text_area('Reference text', str(reference_text))