|
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 |
|
|
|
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_jt_clinical_notes_summarizer", low_cpu_mem_usage=True) |
|
tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_jt_clinical_notes_summarizer") |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_text = st.text_area("Notes:", prompt) |
|
if st.button('Summarize'): |
|
|
|
final_input = f"""[Notes]: {input_text}\n[Summary]: """ |
|
st.write("Summary:") |
|
st.write(summarize_function(final_input)) |
|
|
|
|