Bryan Mildort
app.py updates
9c9b49c
raw
history blame
9.54 kB
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))