bryanmildort's picture
Update app.py
ab4059d
raw
history blame
8.38 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, 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, 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)
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
[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("Summary:")
st.write(summarize_function(final_input))