|
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 = """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.""" |
|
|
|
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)) |
|
|
|
|