Spaces:
Runtime error
Runtime error
Alex Strick van Linschoten
commited on
Commit
·
22150fc
1
Parent(s):
e198289
update app
Browse files- streamlit_app.py +38 -36
streamlit_app.py
CHANGED
@@ -187,46 +187,48 @@ else:
|
|
187 |
)
|
188 |
|
189 |
if extract_images_checkbox:
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
os.
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
os.path.join(
|
219 |
tmp_dir, filename_without_extension, f"pred-{image}"
|
220 |
),
|
|
|
|
|
221 |
)
|
222 |
-
pdf.
|
223 |
-
|
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 |
|