File size: 4,868 Bytes
18ec88b
 
 
 
412a1f8
09b2153
171b76a
18ec88b
9355297
18ec88b
2d0e2ce
18ec88b
 
 
 
944aa34
c5d3b2b
9b14a58
8441878
 
 
d94dfde
 
 
 
680b3f7
8997302
c5d3b2b
f8f1cfb
c5d3b2b
 
2537ff0
18ec88b
 
 
 
e818191
b3da830
 
 
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
 
e818191
 
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
 
 
18ec88b
 
 
 
 
 
 
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
import streamlit as st

def summarize_function(notes):
    notes_input = tokenizer(notes, return_tensors='pt')
    output = model(**notes_input)
    max_length = len(output['logits'][0]) + 40
    # max_length = len(notes.split(' ')) + 40
    input_ids = notes_input.input_ids
    gen_tokens = model.generate(input_ids, do_sample=True, temperature = 0.5, max_length=max_length)
    gen_text = tokenizer.batch_decode(gen_tokens)[0]
    return gen_text[len(notes):]

st.markdown("<h1 style='text-align: center; color: #489DDB;'>GPT Clinical Notes Summarizer</h1>", unsafe_allow_html=True)
st.markdown("<h6 style='text-align: center; color: #489DDB;'>by Bryan Mildort</h1>", unsafe_allow_html=True)

from transformers import AutoTokenizer, GPTJForCausalLM
# from accelerate import infer_auto_device_map
import torch
device = "cuda:0" if torch.cuda.is_available() else "cpu"
device_str = f"""Device being used: {device}"""
st.write(device_str)

# model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt-clinical-notes-summarizer", load_in_8bit=True, device_map="auto")
# model = model.to(device)

tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt-clinical-notes-summarizer")
checkpoint = "bryanmildort/gpt-clinical-notes-summarizer"
model = GPTJForCausalLM.from_pretrained(checkpoint)

# device_map = infer_auto_device_map(model, dtype="float16")
# st.write(device_map)

prompt = """Edie Whelan is a 26 yo female who is here for follow-up following an ED visit for palpitations 2 weeks ago. She had a normal workup in the ED consisting of CBC, metabolic panel, cardiac enzymes and and ECG. She states that she has a 5 yr hx of palpitations with SOB, throat tightening, nause and clamminess. these have been increasing in frequency in the past few weeks to 1-2x a day until 2 weeks ago when she had associated numbness in her fingers. She states that there are no precipitating events and these stop on their own. She endorses recent life stressors having bought a condo 3 months ago and lost her job 2 months ago.  She denies fevers, chills, changes in skin/hair/nails or chest pain/tightness. She denies vision or hearing changes. 
PMH: none, Meds: none, Allergies: none, Surgeries: None, Family hx: none
Social: denies caffeine, tobacco, alcohol, and drug use. Is in a monogomous relationship and has sex with condoms"""

prefix = """[Notes]: Ms. Whelan is a 26 yo woman who presents with palpitations, which have recently been occurring more frequently. She reports that she has episodes of 15-30 minutes of heart pounding, which is associated with shortness of breath, nausea, throat tightening, and a hot-to-cold feeling. A couple weeks ago one of these episodes was associated with some transient bilateral finger/hand numbness, which resolved but prompted her to visit the ED. In the last 5 years she has had 3-4 such episodes. However, she has been experiencing them every 2-3 days in the last 3 weeks. The patient notes that she was laid off from work 2 mos ago and is now seeking employment. Denies specific triggers.



ROS: Denies fever, weight loss, heat/cold intolerance, changes to skin or hair

PMH: No other medical issues

MEDs: Not taking any medicines

SHx: No caffeine, EtOH, smoking; sexually active with boyfriend, uses condoms

FHx: Non-contributory


[Summary]: 26 y/o female presents with palpitations, 15-30 minutes of heart pounding, associated with shortness of breath, nausea, throat tightening, and a hot-to-cold feeling, transient bilateral finger/hand numbness, occurring every
[Notes]: HPI: 67 YO F C/O DIFFICULTY FALLING ASLEEP SINCE HER SON DIES 3 WEEKS AGO. SHE WAKES UP EARLY IN THE MORNING AND SLEEPS FOR 4-5 HOURS EVERY NIGHT WITH SLEEP LATENCY OF ABOUT 1 HOUR EVERY NIGHT. SHE DOESN'T FEEL REFRESHED IN  THE MORNING BUT DENIES ANY SNORING DURING SLEEP. SHE ASO FEELS SAD ALL THE TIME, POOR CONCENTRATION, ANHEDONIA, LOW ENERGY BUT DENIES ANY SUICIDAL IDEATION. SHE DENIES ANY TREMORS, HEAT INTOLERANCE OR WEIGHT CHANGES. SHE REPORTS VISUAL HALLUCINATIONS ABOUT HER SON AND AUDITORY HALLUCINATIONS YESTERDAY IRRELEVANT TO THE INCIDENT.  NO FEVER, WEAKNESS, NUMBNESS, RASH OR URINARY OR BOWEL CHANGES.

ROS: NONE EXCEPT AS ABOVE.

PMH: HTN * 15 YEARS.

PSH: NONE.

ALL: NKDA.

MEDS: HCTZ, LISINOPRIL

FH: DEPRESSION IN MOTHER, HTN AND HYPERCHOLERSTEROLEMIA IN FATHER.

SSH: MONOGAMOUS WITH HUSBAND, NON SMOKING, OCCASIONAL ETOH 2-3/WEEK, NO ILLICIT DRUG USE.
[Summary]: 67 y/o female presents with difficulty falling asleep since her son's death 3 weeks ago, wakes up early in the morning and sleeps for 4-5 hours every night with sleep latency of 1 hour, feels sad all the time, poor concentration
"""

input_text = st.text_area("Notes:", prompt)
if st.button('Summarize'):
    final_input = f"""{prefix}\n[Notes]: {input_text}\n[Summary]: """
    st.write("Summary:")
    st.write(summarize_function(final_input))