Sasidhar commited on
Commit
e45e7fb
·
1 Parent(s): 08426ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -8
app.py CHANGED
@@ -86,6 +86,84 @@ pipeline_qa = init_qa_pipeline()
86
 
87
  st.header("Intelligent Document Automation")
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  def get_text_from_ocr_engine():
90
 
91
  return """18 February2020
@@ -141,17 +219,21 @@ if selected_menu == "Upload Document":
141
  elif selected_menu == "Extract Text":
142
  st.write(get_text_from_ocr_engine())
143
  elif selected_menu == "Summarize Document":
144
- text = get_text_from_ocr_engine()
145
  with st.spinner("Summarizing Document..."):
146
- summary_text = pipeline_summarization(text, max_length=130, min_length=10, do_sample=False)
147
- # Show output
148
- st.write(summary_text[0]['summary_text'])
 
149
 
150
  elif selected_menu == "Extract Entities":
151
- text = get_text_from_ocr_engine()
152
- output = pipeline_ner (text)
153
- entities_text =get_formatted_text_for_annotation(output)
154
- annotated_text(*entities_text)
 
 
 
155
 
156
  elif selected_menu == "Get Answers":
157
  st.subheader('Question')
 
86
 
87
  st.header("Intelligent Document Automation")
88
 
89
+ def get_paragraphs_for_summaries():
90
+ paras =[]
91
+ paras.append("""Stephen is a 53 year old gentleman who does general duties police work. He is married and has an
92
+ 18 year old daughter at home. He is right hand dominant. Cigarettes nil, alcohol rare, allergies nil.
93
+ DVTe nil. Past medical history hyperlipidemia and reflux testicular cancer in 2000 and right knee
94
+ reconstruction in 1987. Medications include Nexium and Crestor.""")
95
+ paras.append("""History presenting complaint: Right knee and right elbow injuries. On 12 January 2020, while at work
96
+ he was trying to apprehend a stolen vehicle. The deployed some road spikes onto the road. The
97
+ stolen vehicle went over the road spikes. He was attempting to retrieve the spikes to prevent
98
+ damage to civilian and police vehicles and while he was doing that, he was hit by a police vehicle
99
+ coming from behind. The police vehicle was approximately doing 50 km/hr. The headlight of the
100
+ police car stuck him on the lateral aspect of the right knee. He jumped in the air and flicked in the air
101
+ with his right elbow also hitting the police car before he flung over a barrier. He was able to mobilise
102
+ afterwards when the adrenaline was taking effect. After he cooled down that night he developed
103
+ significant pain in both the elbow and the knee. The elbow seemed to have settled with time but he
104
+ has got slight discomfort on the lateral epicondyle of the right elbow but otherwise no instability,
105
+ clicking, locking or catching of the elbow.""")
106
+ paras.append("""His knee has medial sided pain. It is an annoying type of pain that is present at rear and with activity.
107
+ It feels like it is getting slightly better but his main problem is that he cannot still fully flex his knee as
108
+ he used to do before the accident. He has noticed some clicking ad a little bit of swelling in the knee.
109
+ He has had no instability but he is still a little bit stiff when he first gets up. He has been treated with
110
+ 4 sessions of physiotherapy. He has had two operations on this knee before when it was
111
+ reconstructed which was an open procedure and an anthroscopy later to shave off the cartilage. He
112
+ never got back to playing rugby after his reconstruction but he was able to do martial arts and all his
113
+ policing duties without any problem.""")
114
+ paras.append("""He is mildly overweight, normal gait and no effusion in the knee and a range of motion of 0 to 110
115
+ degrees which cannot be improved passively. His right elbow has full range of motion and is stable.
116
+ He has had an Xray on right elbow showing no fracture and an xray of knee showed early medial
117
+ compartment osteoarthritis. He has got new clicking in his knee and has been advised to get an MRI
118
+ scan.""")
119
+ paras.append("""As far as his right elbow is concerned, he should reduce weight lifting activity and any repetitive right
120
+ upper limb activity that causes any discomfort. His right knee requires an MRI scan to look for any
121
+ loose bodies and I will see him with the results of the scan. In the meantime, he can continue with
122
+ his general policing duties which he has anyways been doing since the accident""")
123
+ return paras
124
+
125
+ def get_paragraphs_for_entities():
126
+ paras =[]
127
+ paras.append("""18 February2020
128
+ Dr Christine Fowler""")
129
+ paras.append("""Dear Christine,
130
+ Re: Stephen Parrot""")
131
+ paras.append("""Stephen is a 53 year old gentleman who does general duties police work. He is married and has an
132
+ 18 year old daughter at home. He is right hand dominant. Cigarettes nil, alcohol rare, allergies nil.
133
+ DVTe nil. Past medical history hyperlipidemia and reflux testicular cancer in 2000 and right knee
134
+ reconstruction in 1987. Medications include Nexium and Crestor.""")
135
+ paras.append("""History presenting complaint: Right knee and right elbow injuries. On 12 January 2020, while at work
136
+ he was trying to apprehend a stolen vehicle. The deployed some road spikes onto the road. The
137
+ stolen vehicle went over the road spikes. He was attempting to retrieve the spikes to prevent
138
+ damage to civilian and police vehicles and while he was doing that, he was hit by a police vehicle
139
+ coming from behind. The police vehicle was approximately doing 50 km/hr. The headlight of the
140
+ police car stuck him on the lateral aspect of the right knee. He jumped in the air and flicked in the air
141
+ with his right elbow also hitting the police car before he flung over a barrier. He was able to mobilise
142
+ afterwards when the adrenaline was taking effect. After he cooled down that night he developed
143
+ significant pain in both the elbow and the knee. The elbow seemed to have settled with time but he
144
+ has got slight discomfort on the lateral epicondyle of the right elbow but otherwise no instability,
145
+ clicking, locking or catching of the elbow.""")
146
+ paras.append("""His knee has medial sided pain. It is an annoying type of pain that is present at rear and with activity.
147
+ It feels like it is getting slightly better but his main problem is that he cannot still fully flex his knee as
148
+ he used to do before the accident. He has noticed some clicking ad a little bit of swelling in the knee.
149
+ He has had no instability but he is still a little bit stiff when he first gets up. He has been treated with
150
+ 4 sessions of physiotherapy. He has had two operations on this knee before when it was
151
+ reconstructed which was an open procedure and an anthroscopy later to shave off the cartilage. He
152
+ never got back to playing rugby after his reconstruction but he was able to do martial arts and all his
153
+ policing duties without any problem.""")
154
+ paras.append("""He is mildly overweight, normal gait and no effusion in the knee and a range of motion of 0 to 110
155
+ degrees which cannot be improved passively. His right elbow has full range of motion and is stable.
156
+ He has had an Xray on right elbow showing no fracture and an xray of knee showed early medial
157
+ compartment osteoarthritis. He has got new clicking in his knee and has been advised to get an MRI
158
+ scan.""")
159
+ paras.append("""As far as his right elbow is concerned, he should reduce weight lifting activity and any repetitive right
160
+ upper limb activity that causes any discomfort. His right knee requires an MRI scan to look for any
161
+ loose bodies and I will see him with the results of the scan. In the meantime, he can continue with
162
+ his general policing duties which he has anyways been doing since the accident""")
163
+ paras.append("""Kind regards,
164
+ Dr Jason Sanders""")
165
+ return paras
166
+
167
  def get_text_from_ocr_engine():
168
 
169
  return """18 February2020
 
219
  elif selected_menu == "Extract Text":
220
  st.write(get_text_from_ocr_engine())
221
  elif selected_menu == "Summarize Document":
222
+ paragraphs= get_paragraphs_for_summaries()
223
  with st.spinner("Summarizing Document..."):
224
+ for text in paragraphs:
225
+ summary_text = pipeline_summarization(text, max_length=130, min_length=10, do_sample=False)
226
+ # Show output
227
+ st.write(summary_text[0]['summary_text'])
228
 
229
  elif selected_menu == "Extract Entities":
230
+ paragraphs= get_paragraphs_for_entities()
231
+
232
+ with st.spinner("Extracting Entities..."):
233
+ for text in paragraphs:
234
+ output = pipeline_ner (text)
235
+ entities_text =get_formatted_text_for_annotation(output)
236
+ annotated_text(*entities_text)
237
 
238
  elif selected_menu == "Get Answers":
239
  st.subheader('Question')