Spaces:
Build error
Build error
Change layout
Browse files
app.py
CHANGED
@@ -369,15 +369,13 @@ def main():
|
|
369 |
st.title('Table Extraction Demo')
|
370 |
st.write('\n')
|
371 |
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
|
376 |
-
st.
|
377 |
-
st.set_option('deprecation.showfileUploaderEncoding', False)
|
378 |
-
filename = st.sidebar.file_uploader('Upload files', type=['png', 'jpeg', 'jpg'])
|
379 |
|
380 |
-
if st.
|
381 |
|
382 |
if filename is None:
|
383 |
st.sidebar.write('Please upload an image')
|
@@ -385,40 +383,48 @@ def main():
|
|
385 |
else:
|
386 |
print(filename)
|
387 |
pil_img = PIL.Image.open(filename)
|
388 |
-
cols[0].image(pil_img)
|
389 |
|
390 |
detection_result = table_detection(pil_img)
|
391 |
crop_images, vis_det_img = crop_image(pil_img, detection_result)
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
423 |
|
424 |
if __name__ == '__main__':
|
|
|
369 |
st.title('Table Extraction Demo')
|
370 |
st.write('\n')
|
371 |
|
372 |
+
tabs = st.tabs(
|
373 |
+
['Table Detection', 'Table Structure Recognition']
|
374 |
+
)
|
375 |
|
376 |
+
filename = st.file_uploader('Upload image', type=['png', 'jpeg', 'jpg'])
|
|
|
|
|
377 |
|
378 |
+
if st.button('Analyze image'):
|
379 |
|
380 |
if filename is None:
|
381 |
st.sidebar.write('Please upload an image')
|
|
|
383 |
else:
|
384 |
print(filename)
|
385 |
pil_img = PIL.Image.open(filename)
|
|
|
386 |
|
387 |
detection_result = table_detection(pil_img)
|
388 |
crop_images, vis_det_img = crop_image(pil_img, detection_result)
|
389 |
+
|
390 |
+
with tabs[0]:
|
391 |
+
st.image(vis_det_img)
|
392 |
+
|
393 |
+
with tabs[1]:
|
394 |
+
str_cols = st.columns((len(crop_images), ) * 5)
|
395 |
+
str_cols[0].subheader('Table image')
|
396 |
+
str_cols[1].subheader('OCR result')
|
397 |
+
str_cols[2].subheader('Structure result')
|
398 |
+
str_cols[3].subheader('Cells result')
|
399 |
+
str_cols[4].subheader('CSV result')
|
400 |
+
|
401 |
+
for i, img in enumerate(crop_images):
|
402 |
+
ocr_result = ocr(img)
|
403 |
+
structure_result = table_structure(img)
|
404 |
+
table_structures, cells, confidence_score = convert_stucture(ocr_result, img, structure_result)
|
405 |
+
cells = extract_text_from_cells(cells)
|
406 |
+
html_result = cells_to_html(cells)
|
407 |
+
df, csv_result = cells_to_csv(cells)
|
408 |
+
#print(df)
|
409 |
+
|
410 |
+
vis_ocr_img = visualize_ocr(img, ocr_result)
|
411 |
+
vis_str_img = visualize_structure(img, structure_result)
|
412 |
+
vis_cells_img = visualize_cells(img, cells)
|
413 |
+
|
414 |
+
str_cols[0].image(img)
|
415 |
+
str_cols[1].image(vis_ocr_img)
|
416 |
+
str_cols[2].image(vis_str_img)
|
417 |
+
str_cols[3].image(vis_cells_img)
|
418 |
+
|
419 |
+
try:
|
420 |
+
str_cols[4].dataframe(df)
|
421 |
+
except:
|
422 |
+
pass
|
423 |
+
|
424 |
+
str_cols[4].download_button('Download table', csv_result, f'table-{i}.csv', 'text/csv', key=f'download-csv-{i}')
|
425 |
+
|
426 |
+
st.write('\n')
|
427 |
+
st.markdown(html_result, unsafe_allow_html=True)
|
428 |
|
429 |
|
430 |
if __name__ == '__main__':
|