bryanmildort commited on
Commit
0a54fdf
·
1 Parent(s): 9c9b49c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -106
app.py CHANGED
@@ -1,143 +1,92 @@
1
  import streamlit as st
2
 
3
  def summarize_function(notes):
4
- notes_input = tokenizer(notes, return_tensors='pt')
5
- output = model(**notes_input)
6
- max_length = len(output['logits'][0]) + 60
7
- input_ids = notes_input.input_ids
8
- gen_tokens = model.generate(input_ids, do_sample=True, top_k=0, temperature = 0.75, max_length=max_length)
9
- gen_text = tokenizer.batch_decode(gen_tokens)[0]
10
  st.write('Summary: ')
11
  return gen_text[len(notes):]
12
 
13
  st.markdown("<h1 style='text-align: center; color: #489DDB;'>GPT Clinical Notes Summarizer 0.1v</h1>", unsafe_allow_html=True)
14
  st.markdown("<h6 style='text-align: center; color: #489DDB;'>by Bryan Mildort</h1>", unsafe_allow_html=True)
15
 
16
- from transformers import AutoTokenizer, AutoModelForCausalLM
17
  # from accelerate import infer_auto_device_map
18
  import torch
19
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
20
  device_str = f"""Device being used: {device}"""
21
  st.write(device_str)
22
-
23
- # model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt-clinical-notes-summarizer", load_in_8bit=True, device_map="auto")
24
- #
25
-
26
- # tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt-clinical-notes-summarizer")
27
- # checkpoint = "bryanmildort/gpt-clinical-notes-summarizer"
28
- # model = GPTJForCausalLM.from_pretrained(checkpoint)
29
-
30
- model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt_jt_clinical_notes_summarizer", low_cpu_mem_usage=True)
31
- tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_jt_clinical_notes_summarizer")
32
- # model = model.to(device)
33
-
34
  # device_map = infer_auto_device_map(model, dtype="float16")
35
  # st.write(device_map)
36
 
37
- <<<<<<< HEAD
38
- 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.
39
- ROS negative
40
- PMH is not a known medical condition. Meds tylenol when she has a headache. Alles NKDA. PSH none Hospi 2times when delivery
41
- SH No smoking or illicit drugs. EOH 1,2 beers/wk socially since becoming an adult.
42
- Sx is active with her husband. Never tested for HIV. no history of STDs
43
- OBGYN LMP 1wk ago, regular, 5days/28days cycle, 5pads/heavy day, menarch 11-12yo
44
- FH's father died of a heart attack at 65. mother is healthy"""
45
- =======
46
- 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."""
47
- >>>>>>> b6718ddb461224aa1814d348061bd8f9fe6200ec
48
-
49
- 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.
50
-
51
-
52
-
53
- ROS: Denies fever, weight loss, heat/cold intolerance, changes to skin or hair
54
-
55
- PMH: No other medical issues
56
-
57
- MEDs: Not taking any medicines
58
-
59
- SHx: No caffeine, EtOH, smoking; sexually active with boyfriend, uses condoms
60
-
61
- FHx: Non-contributory
62
-
63
-
64
- [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
65
- [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.
66
-
67
- PMH: Frequent back pains/muscle spasms
68
-
69
- Meds: Motrins - 1x/week for >10y
70
-
71
- FHx: Parents healthy. Paternal uncle - bleeding ulcer
72
-
73
- SHx: Works in construction. Was drinking 1-2 beers/week stopped due to abd pain. No drugs. 0.5-1ppd for 20y
74
-
75
- ROS: Per HPI
76
-
77
-
78
- [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
79
- """
80
- # [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.
81
-
82
- # ROS: NONE EXCEPT AS ABOVE.
83
-
84
- # PMH: HTN * 15 YEARS.
85
-
86
- # PSH: NONE.
87
-
88
- # ALL: NKDA.
89
-
90
- # MEDS: HCTZ, LISINOPRIL
91
-
92
- # FH: DEPRESSION IN MOTHER, HTN AND HYPERCHOLERSTEROLEMIA IN FATHER.
93
-
94
- # SSH: MONOGAMOUS WITH HUSBAND, NON SMOKING, OCCASIONAL ETOH 2-3/WEEK, NO ILLICIT DRUG USE.
95
- # [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,
96
- # [Notes]: 44 yo F c/o irregular periods x 3 years
97
-
98
- # 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.
99
-
100
- # OB/GYN: LMP 3 years ago, menarche 14. G2P2, no abortions, Last pap smear was NL 1 yr ago
101
-
102
- # ROS: Except above
103
-
104
- # Meds: HCTZ
105
-
106
- # All:NKDA
107
 
108
- # PMH: HTN
109
 
110
- # PSH: Nil
111
 
112
- # FH: Mother-osteoarthritis, overweight, brother-HTN
113
 
114
- # SH: nil smoking or drugs, occasional EtOH. Sexually active with husbandf onl. Walks 3-4 x a week.
115
 
116
- # PMH:
117
- # [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
118
- # [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.
 
 
 
119
 
 
 
 
 
 
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
- # ROs: neg. unless noted above.
 
 
 
 
123
 
124
- # Pmh: None
 
125
 
126
- # FAm Hx: mom healthy, dad died of a heart attack
127
 
128
- # Social Hx: drinks wine, non smoker, no drugs, married with 2 kids. low sexual libido but happy with husband. College lecturer.
129
 
130
- # Meds: tylenol sometimes
131
 
132
- # allergies: NKDA
133
 
 
 
 
134
 
135
- # [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
136
- # """
137
 
138
  input_text = st.text_area("Notes:", prompt)
139
  if st.button('Summarize'):
140
- # final_input = f"""{prefix}\n[Notes]: {input_text}\n[Summary]: """
141
- final_input = f"""[Notes]: {input_text}\n[Summary]: """
142
  st.write(summarize_function(final_input))
143
 
 
1
  import streamlit as st
2
 
3
  def summarize_function(notes):
4
+ gen_text = pipe(notes, max_length=(len(notes.split(' '))*2*1.225), temperature=0.8, num_return_sequences=1, top_p=0.2)[0]['generated_text']
 
 
 
 
 
5
  st.write('Summary: ')
6
  return gen_text[len(notes):]
7
 
8
  st.markdown("<h1 style='text-align: center; color: #489DDB;'>GPT Clinical Notes Summarizer 0.1v</h1>", unsafe_allow_html=True)
9
  st.markdown("<h6 style='text-align: center; color: #489DDB;'>by Bryan Mildort</h1>", unsafe_allow_html=True)
10
 
11
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
12
  # from accelerate import infer_auto_device_map
13
  import torch
14
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
15
  device_str = f"""Device being used: {device}"""
16
  st.write(device_str)
 
 
 
 
 
 
 
 
 
 
 
 
17
  # device_map = infer_auto_device_map(model, dtype="float16")
18
  # st.write(device_map)
19
 
20
+ model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt_neo_notes_summary", low_cpu_mem_usage=True)
21
+ tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_neo_notes_summary")
22
+ model = model.to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
25
 
26
+ prompt = """Admission Date: 2130-4-14 Discharge Date: 2130-4-17
27
 
28
+ Date of Birth: 2082-12-11 Sex: M
29
 
30
+ Service: #58
31
 
32
+ HISTORY OF PRESENT ILLNESS: Mr. Jefferson is a 47 year-old man
33
+ with extreme obesity with a body weight of 440 pounds who is
34
+ 5'7" tall and has a BMI of 69. He has had numerous weight
35
+ loss programs in the past without significant long term
36
+ effect and also has significant venostasis ulcers in his
37
+ lower extremities. He has no known drug allergies.
38
 
39
+ His only past medical history other then obesity is
40
+ osteoarthritis for which he takes Motrin and smoker's cough
41
+ secondary to smoking one pack per day for many years. He has
42
+ used other narcotics, cocaine and marijuana, but has been
43
+ clean for about fourteen years.
44
 
45
+ He was admitted to the General Surgery Service status post
46
+ gastric bypass surgery on 2130-4-14. The surgery was
47
+ uncomplicated, however, Mr. Jefferson was admitted to the Surgical
48
+ Intensive Care Unit after his gastric bypass secondary to
49
+ unable to extubate secondary to a respiratory acidosis. The
50
+ patient had decreased urine output, but it picked up with
51
+ intravenous fluid hydration. He was successfully extubated
52
+ on 4-15 in the evening and was transferred to the floor
53
+ on 2130-4-16 without difficulty. He continued to have
54
+ slightly labored breathing and was requiring a face tent mask
55
+ to keep his saturations in the high 90s. However, was
56
+ advanced according to schedule and tolerated a stage two diet
57
+ and was transferred to the appropriate pain management. He
58
+ was out of bed without difficulty and on postoperative day
59
+ three he was advanced to a stage three diet and then slowly
60
+ was discontinued. He continued to use a face tent overnight,
61
+ but this was discontinued during the day and he was advanced
62
+ to all of the usual changes for postoperative day three
63
+ gastric bypass patient. He will be discharged home today
64
+ postoperative day three in stable condition status post
65
+ gastric bypass.
66
 
67
+ DISCHARGE MEDICATIONS: Vitamin B-12 1 mg po q.d., times two
68
+ months, Zantac 150 mg po b.i.d. times two months, Actigall
69
+ 300 mg po b.i.d. times six months and Roxicet elixir one to
70
+ two teaspoons q 4 hours prn and Albuterol Atrovent meter dose
71
+ inhaler one to two puffs q 4 to 6 hours prn.
72
 
73
+ He will follow up with Dr. Morrow in approximately two weeks as
74
+ well as with the Lowery Medical Center Clinic.
75
 
 
76
 
77
+ Kevin Gonzalez, M.D. R35052373
78
 
79
+ Dictated By:Dotson
80
 
81
+ MEDQUIST36
82
 
83
+ D: 2130-4-17 08:29
84
+ T: 2130-4-18 08:31
85
+ JOB#: Job Number 20340"""
86
 
 
 
87
 
88
  input_text = st.text_area("Notes:", prompt)
89
  if st.button('Summarize'):
90
+ final_input = f"""[Notes]:\n{input_text}\n[Summary]:\n"""
 
91
  st.write(summarize_function(final_input))
92