bryanmildort commited on
Commit
cf9b772
·
1 Parent(s): a8a1c1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -18
app.py CHANGED
@@ -13,38 +13,35 @@ st.markdown("<h6 style='text-align: center; color: #489DDB;'>by Bryan Mildort</h
13
 
14
  from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
15
  # from accelerate import infer_auto_device_map
16
- import torch
17
  # device = "cuda:0" if torch.cuda.is_available() else "cpu"
18
  # device_str = f"""Device being used: {device}"""
19
  # st.write(device_str)
20
  # device_map = infer_auto_device_map(model, dtype="float16")
21
  # st.write(device_map)
22
 
23
- model = AutoModelForCausalLM.from_pretrained("bryanmildort/gpt_neo_notes", low_cpu_mem_usage=True).cuda()
24
- tokenizer = AutoTokenizer.from_pretrained("bryanmildort/gpt_neo_notes")
 
 
 
25
  # model = model.to(device)
26
 
27
- pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
28
 
29
  prompt = """Admission Date: 2130-4-14 Discharge Date: 2130-4-17
30
-
31
  Date of Birth: 2082-12-11 Sex: M
32
-
33
  Service: #58
34
-
35
  HISTORY OF PRESENT ILLNESS: Mr. Jefferson is a 47 year-old man
36
  with extreme obesity with a body weight of 440 pounds who is
37
  5'7" tall and has a BMI of 69. He has had numerous weight
38
  loss programs in the past without significant long term
39
  effect and also has significant venostasis ulcers in his
40
  lower extremities. He has no known drug allergies.
41
-
42
  His only past medical history other then obesity is
43
  osteoarthritis for which he takes Motrin and smoker's cough
44
  secondary to smoking one pack per day for many years. He has
45
  used other narcotics, cocaine and marijuana, but has been
46
  clean for about fourteen years.
47
-
48
  He was admitted to the General Surgery Service status post
49
  gastric bypass surgery on 2130-4-14. The surgery was
50
  uncomplicated, however, Mr. Jefferson was admitted to the Surgical
@@ -66,23 +63,16 @@ to all of the usual changes for postoperative day three
66
  gastric bypass patient. He will be discharged home today
67
  postoperative day three in stable condition status post
68
  gastric bypass.
69
-
70
  DISCHARGE MEDICATIONS: Vitamin B-12 1 mg po q.d., times two
71
  months, Zantac 150 mg po b.i.d. times two months, Actigall
72
  300 mg po b.i.d. times six months and Roxicet elixir one to
73
  two teaspoons q 4 hours prn and Albuterol Atrovent meter dose
74
  inhaler one to two puffs q 4 to 6 hours prn.
75
-
76
  He will follow up with Dr. Morrow in approximately two weeks as
77
  well as with the Lowery Medical Center Clinic.
78
-
79
-
80
  Kevin Gonzalez, M.D. R35052373
81
-
82
  Dictated By:Dotson
83
-
84
  MEDQUIST36
85
-
86
  D: 2130-4-17 08:29
87
  T: 2130-4-18 08:31
88
  JOB#: Job Number 20340"""
@@ -91,5 +81,4 @@ JOB#: Job Number 20340"""
91
  input_text = st.text_area("Notes:", prompt)
92
  if st.button('Summarize'):
93
  final_input = f"""[Notes]:\n{input_text}\n[Summary]:\n"""
94
- st.write(summarize_function(final_input))
95
-
 
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
+ @st.cache(allow_output_mutation=True)
23
+ def load_model():
24
+ model = pipeline("text-generation", model="bryanmildort/gpt_neo_notes")
25
+ return model
26
+
27
  # model = model.to(device)
28
 
29
+ pipe = load_model()
30
 
31
  prompt = """Admission Date: 2130-4-14 Discharge Date: 2130-4-17
 
32
  Date of Birth: 2082-12-11 Sex: M
 
33
  Service: #58
 
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
  His only past medical history other then obesity is
41
  osteoarthritis for which he takes Motrin and smoker's cough
42
  secondary to smoking one pack per day for many years. He has
43
  used other narcotics, cocaine and marijuana, but has been
44
  clean for about fourteen years.
 
45
  He was admitted to the General Surgery Service status post
46
  gastric bypass surgery on 2130-4-14. The surgery was
47
  uncomplicated, however, Mr. Jefferson was admitted to the Surgical
 
63
  gastric bypass patient. He will be discharged home today
64
  postoperative day three in stable condition status post
65
  gastric bypass.
 
66
  DISCHARGE MEDICATIONS: Vitamin B-12 1 mg po q.d., times two
67
  months, Zantac 150 mg po b.i.d. times two months, Actigall
68
  300 mg po b.i.d. times six months and Roxicet elixir one to
69
  two teaspoons q 4 hours prn and Albuterol Atrovent meter dose
70
  inhaler one to two puffs q 4 to 6 hours prn.
 
71
  He will follow up with Dr. Morrow in approximately two weeks as
72
  well as with the Lowery Medical Center Clinic.
 
 
73
  Kevin Gonzalez, M.D. R35052373
 
74
  Dictated By:Dotson
 
75
  MEDQUIST36
 
76
  D: 2130-4-17 08:29
77
  T: 2130-4-18 08:31
78
  JOB#: Job Number 20340"""
 
81
  input_text = st.text_area("Notes:", prompt)
82
  if st.button('Summarize'):
83
  final_input = f"""[Notes]:\n{input_text}\n[Summary]:\n"""
84
+ st.write(summarize_function(final_input))