Spaces:
Runtime error
Runtime error
Commit ·
a2b2aea
0
Parent(s):
Duplicate from bryanmildort/gpt-notes-summarizer-demo-cpu-1
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +94 -0
- requirements.txt +7 -0
.gitattributes
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Gpt Notes Summarizer Demo
|
| 3 |
+
emoji: 🏢
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.17.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
duplicated_from: bryanmildort/gpt-notes-summarizer-demo-cpu-1
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
def summarize_function(notes):
|
| 4 |
+
gen_text = pipe(notes, max_length=(len(notes.split(' '))*2*1.225), temperature=0.8, num_return_sequences=1, top_p=0.2)[0]['generated_text'][len(notes):]
|
| 5 |
+
for i in range(len(gen_text)):
|
| 6 |
+
if gen_text[-i-8:].startswith('[Notes]:'):
|
| 7 |
+
gen_text = gen_text[:-i-8]
|
| 8 |
+
st.write('Summary: ')
|
| 9 |
+
return gen_text
|
| 10 |
+
|
| 11 |
+
st.markdown("<h1 style='text-align: center; color: #489DDB;'>GPT Clinical Notes Summarizer 0.1v</h1>", unsafe_allow_html=True)
|
| 12 |
+
st.markdown("<h6 style='text-align: center; color: #489DDB;'>by Bryan Mildort</h1>", unsafe_allow_html=True)
|
| 13 |
+
|
| 14 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 15 |
+
# from accelerate import infer_auto_device_map
|
| 16 |
+
# device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 17 |
+
# device_str = f"""Device being used: {device}"""
|
| 18 |
+
# st.write(device_str)
|
| 19 |
+
# device_map = infer_auto_device_map(model, dtype="float16")
|
| 20 |
+
# st.write(device_map)
|
| 21 |
+
|
| 22 |
+
model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt_neo_notes", low_cpu_mem_usage=True)
|
| 23 |
+
tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_neo_notes")
|
| 24 |
+
# model = model.to(device)
|
| 25 |
+
|
| 26 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 27 |
+
|
| 28 |
+
prompt = """Admission Date: 2130-4-14 Discharge Date: 2130-4-17
|
| 29 |
+
|
| 30 |
+
Date of Birth: 2082-12-11 Sex: M
|
| 31 |
+
|
| 32 |
+
Service: #58
|
| 33 |
+
|
| 34 |
+
HISTORY OF PRESENT ILLNESS: Mr. Jefferson is a 47 year-old man
|
| 35 |
+
with extreme obesity with a body weight of 440 pounds who is
|
| 36 |
+
5'7" tall and has a BMI of 69. He has had numerous weight
|
| 37 |
+
loss programs in the past without significant long term
|
| 38 |
+
effect and also has significant venostasis ulcers in his
|
| 39 |
+
lower extremities. He has no known drug allergies.
|
| 40 |
+
|
| 41 |
+
His only past medical history other then obesity is
|
| 42 |
+
osteoarthritis for which he takes Motrin and smoker's cough
|
| 43 |
+
secondary to smoking one pack per day for many years. He has
|
| 44 |
+
used other narcotics, cocaine and marijuana, but has been
|
| 45 |
+
clean for about fourteen years.
|
| 46 |
+
|
| 47 |
+
He was admitted to the General Surgery Service status post
|
| 48 |
+
gastric bypass surgery on 2130-4-14. The surgery was
|
| 49 |
+
uncomplicated, however, Mr. Jefferson was admitted to the Surgical
|
| 50 |
+
Intensive Care Unit after his gastric bypass secondary to
|
| 51 |
+
unable to extubate secondary to a respiratory acidosis. The
|
| 52 |
+
patient had decreased urine output, but it picked up with
|
| 53 |
+
intravenous fluid hydration. He was successfully extubated
|
| 54 |
+
on 4-15 in the evening and was transferred to the floor
|
| 55 |
+
on 2130-4-16 without difficulty. He continued to have
|
| 56 |
+
slightly labored breathing and was requiring a face tent mask
|
| 57 |
+
to keep his saturations in the high 90s. However, was
|
| 58 |
+
advanced according to schedule and tolerated a stage two diet
|
| 59 |
+
and was transferred to the appropriate pain management. He
|
| 60 |
+
was out of bed without difficulty and on postoperative day
|
| 61 |
+
three he was advanced to a stage three diet and then slowly
|
| 62 |
+
was discontinued. He continued to use a face tent overnight,
|
| 63 |
+
but this was discontinued during the day and he was advanced
|
| 64 |
+
to all of the usual changes for postoperative day three
|
| 65 |
+
gastric bypass patient. He will be discharged home today
|
| 66 |
+
postoperative day three in stable condition status post
|
| 67 |
+
gastric bypass.
|
| 68 |
+
|
| 69 |
+
DISCHARGE MEDICATIONS: Vitamin B-12 1 mg po q.d., times two
|
| 70 |
+
months, Zantac 150 mg po b.i.d. times two months, Actigall
|
| 71 |
+
300 mg po b.i.d. times six months and Roxicet elixir one to
|
| 72 |
+
two teaspoons q 4 hours prn and Albuterol Atrovent meter dose
|
| 73 |
+
inhaler one to two puffs q 4 to 6 hours prn.
|
| 74 |
+
|
| 75 |
+
He will follow up with Dr. Morrow in approximately two weeks as
|
| 76 |
+
well as with the Lowery Medical Center Clinic.
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Kevin Gonzalez, M.D. R35052373
|
| 80 |
+
|
| 81 |
+
Dictated By:Dotson
|
| 82 |
+
|
| 83 |
+
MEDQUIST36
|
| 84 |
+
|
| 85 |
+
D: 2130-4-17 08:29
|
| 86 |
+
T: 2130-4-18 08:31
|
| 87 |
+
JOB#: Job Number 20340"""
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
input_text = st.text_area("Notes:", prompt)
|
| 91 |
+
if st.button('Summarize'):
|
| 92 |
+
final_input = f"""[Notes]:\n{input_text}\n[Summary]:\n"""
|
| 93 |
+
st.write(summarize_function(final_input))
|
| 94 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
datasets
|
| 5 |
+
accelerate
|
| 6 |
+
bitsandbytes
|
| 7 |
+
torch
|