bryanmildort commited on
Commit
b878344
1 Parent(s): 328fff1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -63
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
  import re
3
 
4
  def summarize_function(notes):
@@ -24,78 +25,28 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
24
  def load_model():
25
  model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt_neo_notes", low_cpu_mem_usage=True)
26
  tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_neo_notes")
27
- pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
28
- return pipe
29
 
30
- # model = model.to(device)
31
 
32
  pipe = load_model()
33
 
34
- prompt = """Admission Date: 2130-4-14 Discharge Date: 2130-4-17
35
 
36
- Date of Birth: 2082-12-11 Sex: M
37
-
38
- Service: #58
39
-
40
- HISTORY OF PRESENT ILLNESS: Mr. Jefferson is a 47 year-old man
41
- with extreme obesity with a body weight of 440 pounds who is
42
- 5'7" tall and has a BMI of 69. He has had numerous weight
43
- loss programs in the past without significant long term
44
- effect and also has significant venostasis ulcers in his
45
- lower extremities. He has no known drug allergies.
46
-
47
- His only past medical history other then obesity is
48
- osteoarthritis for which he takes Motrin and smoker's cough
49
- secondary to smoking one pack per day for many years. He has
50
- used other narcotics, cocaine and marijuana, but has been
51
- clean for about fourteen years.
52
-
53
- He was admitted to the General Surgery Service status post
54
- gastric bypass surgery on 2130-4-14. The surgery was
55
- uncomplicated, however, Mr. Jefferson was admitted to the Surgical
56
- Intensive Care Unit after his gastric bypass secondary to
57
- unable to extubate secondary to a respiratory acidosis. The
58
- patient had decreased urine output, but it picked up with
59
- intravenous fluid hydration. He was successfully extubated
60
- on 4-15 in the evening and was transferred to the floor
61
- on 2130-4-16 without difficulty. He continued to have
62
- slightly labored breathing and was requiring a face tent mask
63
- to keep his saturations in the high 90s. However, was
64
- advanced according to schedule and tolerated a stage two diet
65
- and was transferred to the appropriate pain management. He
66
- was out of bed without difficulty and on postoperative day
67
- three he was advanced to a stage three diet and then slowly
68
- was discontinued. He continued to use a face tent overnight,
69
- but this was discontinued during the day and he was advanced
70
- to all of the usual changes for postoperative day three
71
- gastric bypass patient. He will be discharged home today
72
- postoperative day three in stable condition status post
73
- gastric bypass.
74
-
75
- DISCHARGE MEDICATIONS: Vitamin B-12 1 mg po q.d., times two
76
- months, Zantac 150 mg po b.i.d. times two months, Actigall
77
- 300 mg po b.i.d. times six months and Roxicet elixir one to
78
- two teaspoons q 4 hours prn and Albuterol Atrovent meter dose
79
- inhaler one to two puffs q 4 to 6 hours prn.
80
-
81
- He will follow up with Dr. Morrow in approximately two weeks as
82
- well as with the Lowery Medical Center Clinic.
83
-
84
-
85
- Kevin Gonzalez, M.D. R35052373
86
-
87
- Dictated By:Dotson
88
-
89
- MEDQUIST36
90
-
91
- D: 2130-4-17 08:29
92
- T: 2130-4-18 08:31
93
- JOB#: Job Number 20340"""
94
 
 
 
95
 
 
96
  input_text = st.text_area("Notes:", prompt)
97
  if st.button('Summarize'):
98
  parsed_input = re.sub(r'\n\s*\n', '\n\n', input_text)
99
  parsed_input = re.sub(r'\n+', '\n',parsed_input)
100
  final_input = f"""[Notes]:\n{parsed_input}\n[Summary]:\n"""
101
- st.write(summarize_function(final_input))
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
  import re
4
 
5
  def summarize_function(notes):
 
25
  def load_model():
26
  model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt_neo_notes", low_cpu_mem_usage=True)
27
  tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_neo_notes")
28
+ return pipeline("text-generation", model=model, tokenizer=tokenizer)
 
29
 
30
+ model = model.to(device)
31
 
32
  pipe = load_model()
33
 
 
34
 
35
+ notes_df = pd.read_csv('notes_small.csv')
36
+ examples_tuple = ()
37
+ for i in range(len(notes_df)):
38
+ examples_tuple += (f"Patient {i+1}", )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ example = st.sidebar.selectbox('Example', (examples_tuple), index=0)
41
+ st.write(example)
42
 
43
+ prompt = notes_df.iloc[int(example[-1:])-1].PARSED
44
  input_text = st.text_area("Notes:", prompt)
45
  if st.button('Summarize'):
46
  parsed_input = re.sub(r'\n\s*\n', '\n\n', input_text)
47
  parsed_input = re.sub(r'\n+', '\n',parsed_input)
48
  final_input = f"""[Notes]:\n{parsed_input}\n[Summary]:\n"""
49
+ st.write(summarize_function(final_input))
50
+
51
+
52
+