|
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 |
|
|
|
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 |
|
|
|
import torch |
|
device = "cuda:0" if torch.cuda.is_available() else "cpu" |
|
device_str = f"""Device being used: {device}""" |
|
st.write(device_str) |
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt-clinical-notes-summarizer") |
|
checkpoint = "bryanmildort/gpt-clinical-notes-summarizer" |
|
model = GPTJForCausalLM.from_pretrained(checkpoint) |
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
|