Alex Strick van Linschoten commited on
Commit
22150fc
1 Parent(s): e198289

update app

Browse files
Files changed (1) hide show
  1. streamlit_app.py +38 -36
streamlit_app.py CHANGED
@@ -187,46 +187,48 @@ else:
187
  )
188
 
189
  if extract_images_checkbox:
190
- pdf = FPDF(unit="cm", format="A4")
191
- pdf.set_auto_page_break(0)
192
- imagelist = sorted(
193
- [
194
- i
195
- for i in os.listdir(
196
- os.path.join(tmp_dir, filename_without_extension)
197
- )
198
- if i.endswith("png")
199
- ]
200
- )
201
- for image in imagelist:
202
- with PILImage.open(
203
- os.path.join(tmp_dir, filename_without_extension, image)
204
- ) as img:
205
- size = img.size
206
- width, height = size
207
- if width > height:
208
- pdf.add_page(orientation="L")
209
- else:
210
- pdf.add_page(orientation="P")
211
- pred_dict = get_image_predictions(img)
212
-
213
- total_image_areas += pred_dict["width"] * pred_dict["height"]
214
- total_content_areas += get_content_area(pred_dict)
215
- total_redaction_area += get_redaction_area(pred_dict)
216
-
217
- pred_dict["img"].save(
 
 
 
 
 
 
218
  os.path.join(
219
  tmp_dir, filename_without_extension, f"pred-{image}"
220
  ),
 
 
221
  )
222
- pdf.image(
223
- os.path.join(
224
- tmp_dir, filename_without_extension, f"pred-{image}"
225
- ),
226
- w=pdf.w,
227
- h=pdf.h,
228
- )
229
- pdf.output(report, "F")
230
 
231
  text_output = f"A total of {len(redacted_pages)} pages were redacted. \n\nThe redacted page numbers were: {', '.join(redacted_pages)}. \n\n"
232
 
187
  )
188
 
189
  if extract_images_checkbox:
190
+ with st.spinner('Calculating redaction proportions...'):
191
+ pdf = FPDF(unit="cm", format="A4")
192
+ pdf.set_auto_page_break(0)
193
+ imagelist = sorted(
194
+ [
195
+ i
196
+ for i in os.listdir(
197
+ os.path.join(tmp_dir, filename_without_extension)
198
+ )
199
+ if i.endswith("png")
200
+ ]
201
+ )
202
+ for image in imagelist:
203
+ with PILImage.open(
204
+ os.path.join(tmp_dir, filename_without_extension, image)
205
+ ) as img:
206
+ size = img.size
207
+ width, height = size
208
+ if width > height:
209
+ pdf.add_page(orientation="L")
210
+ else:
211
+ pdf.add_page(orientation="P")
212
+ pred_dict = get_image_predictions(img)
213
+
214
+ total_image_areas += pred_dict["width"] * pred_dict["height"]
215
+ total_content_areas += get_content_area(pred_dict)
216
+ total_redaction_area += get_redaction_area(pred_dict)
217
+
218
+ pred_dict["img"].save(
219
+ os.path.join(
220
+ tmp_dir, filename_without_extension, f"pred-{image}"
221
+ ),
222
+ )
223
+ pdf.image(
224
  os.path.join(
225
  tmp_dir, filename_without_extension, f"pred-{image}"
226
  ),
227
+ w=pdf.w,
228
+ h=pdf.h,
229
  )
230
+ pdf.output(report, "F")
231
+ st.success('Image predictions complete!')
 
 
 
 
 
 
232
 
233
  text_output = f"A total of {len(redacted_pages)} pages were redacted. \n\nThe redacted page numbers were: {', '.join(redacted_pages)}. \n\n"
234