Spaces:
Build error
Build error
Fix bug
Browse files
app.py
CHANGED
|
@@ -193,7 +193,7 @@ def visualize_structure(pil_img, structure_result):
|
|
| 193 |
y2 = int((min_y + h / 2) * height)
|
| 194 |
# print(x1, y1, x2, y2)
|
| 195 |
|
| 196 |
-
if score >=
|
| 197 |
cv2.rectangle(image, (x1, y1), (x2, y2), color=(0, 0, 255))
|
| 198 |
#cv2.putText(image, str(i)+'-'+str(class_id), (x1-10, y1), cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, color=(0,0,255))
|
| 199 |
|
|
@@ -387,18 +387,18 @@ def main():
|
|
| 387 |
else:
|
| 388 |
print(filename)
|
| 389 |
pil_img = PIL.Image.open(filename)
|
|
|
|
| 390 |
|
| 391 |
detection_result = table_detection(pil_img)
|
| 392 |
crop_images, vis_det_img = crop_image(pil_img, detection_result)
|
| 393 |
-
cols[
|
| 394 |
|
| 395 |
-
str_cols = st.columns((len(crop_images), ) *
|
| 396 |
str_cols[0].subheader("Table image")
|
| 397 |
str_cols[1].subheader("OCR result")
|
| 398 |
str_cols[2].subheader("Structure result")
|
| 399 |
str_cols[3].subheader("Cells result")
|
| 400 |
-
str_cols[4].subheader("
|
| 401 |
-
str_cols[5].subheader("CSV result")
|
| 402 |
|
| 403 |
for img in crop_images:
|
| 404 |
ocr_result = ocr(img)
|
|
@@ -407,6 +407,7 @@ def main():
|
|
| 407 |
cells = extract_text_from_cells(cells)
|
| 408 |
html_result = cells_to_html(cells)
|
| 409 |
df, csv_result = cells_to_csv(cells)
|
|
|
|
| 410 |
|
| 411 |
vis_ocr_img = visualize_ocr(img, ocr_result)
|
| 412 |
vis_str_img = visualize_structure(img, structure_result)
|
|
@@ -416,9 +417,10 @@ def main():
|
|
| 416 |
str_cols[1].image(vis_ocr_img)
|
| 417 |
str_cols[2].image(vis_str_img)
|
| 418 |
str_cols[3].image(vis_cells_img)
|
| 419 |
-
str_cols[4].
|
| 420 |
-
str_cols[
|
| 421 |
-
|
|
|
|
| 422 |
|
| 423 |
|
| 424 |
if __name__ == '__main__':
|
|
|
|
| 193 |
y2 = int((min_y + h / 2) * height)
|
| 194 |
# print(x1, y1, x2, y2)
|
| 195 |
|
| 196 |
+
if score >= structure_class_thresholds[structure_class_names[class_id]]:
|
| 197 |
cv2.rectangle(image, (x1, y1), (x2, y2), color=(0, 0, 255))
|
| 198 |
#cv2.putText(image, str(i)+'-'+str(class_id), (x1-10, y1), cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, color=(0,0,255))
|
| 199 |
|
|
|
|
| 387 |
else:
|
| 388 |
print(filename)
|
| 389 |
pil_img = PIL.Image.open(filename)
|
| 390 |
+
cols[0].image(pil_img)
|
| 391 |
|
| 392 |
detection_result = table_detection(pil_img)
|
| 393 |
crop_images, vis_det_img = crop_image(pil_img, detection_result)
|
| 394 |
+
cols[1].image(vis_det_img)
|
| 395 |
|
| 396 |
+
str_cols = st.columns((len(crop_images), ) * 5)
|
| 397 |
str_cols[0].subheader("Table image")
|
| 398 |
str_cols[1].subheader("OCR result")
|
| 399 |
str_cols[2].subheader("Structure result")
|
| 400 |
str_cols[3].subheader("Cells result")
|
| 401 |
+
str_cols[4].subheader("CSV result")
|
|
|
|
| 402 |
|
| 403 |
for img in crop_images:
|
| 404 |
ocr_result = ocr(img)
|
|
|
|
| 407 |
cells = extract_text_from_cells(cells)
|
| 408 |
html_result = cells_to_html(cells)
|
| 409 |
df, csv_result = cells_to_csv(cells)
|
| 410 |
+
print(df)
|
| 411 |
|
| 412 |
vis_ocr_img = visualize_ocr(img, ocr_result)
|
| 413 |
vis_str_img = visualize_structure(img, structure_result)
|
|
|
|
| 417 |
str_cols[1].image(vis_ocr_img)
|
| 418 |
str_cols[2].image(vis_str_img)
|
| 419 |
str_cols[3].image(vis_cells_img)
|
| 420 |
+
#str_cols[4].dataframe(df)
|
| 421 |
+
str_cols[4].download_button("Download table", csv_result, "file.csv", "text/csv", key='download-csv')
|
| 422 |
+
|
| 423 |
+
st.markdown(html_result, unsafe_allow_html=True)
|
| 424 |
|
| 425 |
|
| 426 |
if __name__ == '__main__':
|