File size: 9,538 Bytes
18ec88b
 
 
 
412a1f8
a3a951a
18ec88b
01db17d
18ec88b
01db17d
2d0e2ce
18ec88b
01db17d
18ec88b
 
8a98078
c5d3b2b
9b14a58
8441878
 
 
d94dfde
 
8a98078
d94dfde
8a98078
 
 
 
ab4059d
 
fff902b
f8f1cfb
c5d3b2b
 
2537ff0
9c9b49c
01db17d
 
 
 
 
 
 
9c9b49c
b6718dd
9c9b49c
18ec88b
e818191
b3da830
 
 
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
e818191
b3da830
 
75344d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2d37d6
 
b3da830
a2d37d6
b3da830
a2d37d6
b3da830
a2d37d6
b3da830
a2d37d6
b3da830
a2d37d6
b3da830
a2d37d6
b3da830
a2d37d6
 
 
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
 
 
bc77060
 
 
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
a2d37d6
bc77060
 
a2d37d6
 
18ec88b
df65670
18ec88b
1716ce8
 
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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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]) + 60
    input_ids = notes_input.input_ids
    gen_tokens = model.generate(input_ids, do_sample=True, top_k=0, temperature = 0.75, max_length=max_length)
    gen_text = tokenizer.batch_decode(gen_tokens)[0]
    st.write('Summary: ')
    return gen_text[len(notes):]

st.markdown("<h1 style='text-align: center; color: #489DDB;'>GPT Clinical Notes Summarizer 0.1v</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, AutoModelForCausalLM
# 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")
# 

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

model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt_jt_clinical_notes_summarizer", low_cpu_mem_usage=True)
tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_jt_clinical_notes_summarizer")
# model = model.to(device)

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

<<<<<<< HEAD
prompt = """45 y F c/o nervousness x few weeks, not getting worse or better, constant, was the first time. No alleviating factors. Aggravated before having an English lecture. I work as an English professor, with stress. I also have a sleeping problem, started almost at the same time, and had difficulty falling asleep. They also report excessive appetite. Denies weight changes, healing intolerance, consitpation, dirrhea, black stools, and bladdy stools. Also denies excessive thirst and excessive urination. Mood=just nervous. No heart racing.
ROS negative
PMH is not a known medical condition. Meds tylenol when she has a headache. Alles NKDA. PSH none Hospi 2times when delivery      
SH No smoking or illicit drugs. EOH 1,2 beers/wk socially since becoming an adult.
Sx is active with her husband. Never tested for HIV. no history of STDs
OBGYN LMP 1wk ago, regular, 5days/28days cycle, 5pads/heavy day, menarch 11-12yo
FH's father died of a heart attack at 65. mother is healthy"""
=======
prompt = """81-year-old female with a history of emphysema (not on home O2), who presents with three days of shortness of breath thought by her primary care doctor to be a COPD flare. Two days prior to admission, she was started on a prednisone taper and one day prior to admission she required oxygen at home in order to maintain oxygen saturation greater than 90%. She has also been on levofloxacin and nebulizers, and was not getting better, and presented to the Emergency Room. In the Emergency Room, her oxygen saturation was100% on CPAP. She was not able to be weaned off of this despite nebulizer treatment and Solu-Medrol 125 mg IV x2.Review of systems is negative for the following: Fevers, chills, nausea, vomiting, night sweats, change in weight, gastrointestinal complaints, neurologic changes, rashes, palpitations, orthopnea. Is positive for the following: Chest pressure occasionally with shortness of breath with exertion, some shortness of breath that is positionally related, but is improved with nebulizer treatment."""
>>>>>>> b6718ddb461224aa1814d348061bd8f9fe6200ec

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
[Notes]: Chad Hamilton is a 35yo man with chronic back pain who presents with 2m of epigastric pain and 2w of dark stools. The pt works in construction and for >10y has regularly taken Motrin for back pain. 2m ago he gradually developed a knawing, 5/10 mid-epigastric pain. The pain wakes him up from sleep. It does not radiate. Is associated with nausea - no vomitting. Initially tums helped, but that no longer does. The pain isnt worse with eating but he feels bloated after meals, reducing how much he eats. He denies weight loss, fevers/chills, BRBPR, abnormal taste.

PMH: Frequent back pains/muscle spasms

Meds: Motrins - 1x/week for >10y

FHx: Parents healthy. Paternal uncle - bleeding ulcer

SHx: Works in construction. Was drinking 1-2 beers/week stopped due to abd pain. No drugs. 0.5-1ppd for 20y

ROS: Per HPI


[Summary]: 35yo M with PMHx of chronic back pain c/o epigastric pain for past 2 months, knawing/burning pain, wakes up from sleep, nausea, bloating, dark stools, no weight loss
"""
# [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,
# [Notes]: 44 yo F c/o irregular periods x 3 years

# Her last normal period was 3 years ago.  Periods uses to be for 5 days every 28 days, 3 pads with occasional cramping. Now has 2-6 day cycles which are iiregular, sometimes heavy, other times light, unpredicatble pattern. Reports vaginal dryness in past year and drenching night sweat 1 week ago. No vaginal discharge or itching. No skin or hair changes. Had an episode of nausea and vomitting last week. No mood changes.

# OB/GYN: LMP 3 years ago, menarche 14.  G2P2, no abortions, Last pap smear was NL 1 yr ago

# ROS: Except above

# Meds: HCTZ

# All:NKDA

# PMH: HTN

# PSH: Nil

# FH: Mother-osteoarthritis, overweight, brother-HTN

# SH: nil smoking or drugs, occasional EtOH. Sexually active with husbandf onl. Walks 3-4 x a week. 

# PMH:
# [Summary]: 44 y/o female presents with irregular periods x 3 years, 2-6 day cycles, sometimes heavy, other times light, unpredictable pattern, vaginal dryness, drenching night sweat 1 week ago, nausea and vomiting last week, no mood
# [Notes]: HPI: 45 y/o woman is presents with constant nervousness. She has never had this happen before adn it started a few weeks ago around the time she started teaching Eng lit at college. She is usually not afraid of public speaking she says. She feels overwhelmed all the time and nothing makes it feel better. Sometimes it is unbearable and she cannot fall asleep. She takes care of her 2 children on her own even tho she is married because her husband works a lot and takes care of his parents. No assoc headache, n/v/d, parasthesias, numbness, tingling, sleeps well once she is ASleep and feels rested. No abdominal pain, no UE weakness  or LE weakness. Pt is healthy  otherwise. 



# ROs: neg. unless noted above. 

# Pmh: None

# FAm Hx: mom healthy, dad died of a heart attack 

# Social Hx: drinks wine, non smoker, no drugs, married with 2 kids. low sexual libido but happy with husband.  College lecturer. 

# Meds: tylenol sometimes

# allergies: NKDA


# [Summary]: 45 y/o female presents with constant nervousness for the past few weeks, associated with her new position as a college lecturer, no associated headache, nausea, vomiting, or weakness, drinks wine, non-smoker, no drugs, married with
# """

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