shamikbose89 commited on
Commit
dd3637e
1 Parent(s): f842273

Streamlit has an error with multiple table download buttons

Browse files

When testing with a file that has multiple detected tables, each download button gets the same key causing an error. The proposed change fixes that by appending the table count to the download button key

Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -381,7 +381,7 @@ class TableExtractionPipeline():
381
  return df.to_csv().encode('utf-8')
382
 
383
 
384
- def create_dataframe(self, c3, cells_pytess_result:list, max_cols:int, max_rows:int):
385
  '''Create dataframe using list of cell values of the table, also checks for valid header of dataframe
386
  Args:
387
  cells_pytess_result: list of strings, each element representing a cell in a table
@@ -419,7 +419,7 @@ class TableExtractionPipeline():
419
 
420
  c3.dataframe(df)
421
  csv = self.convert_df(df)
422
- c3.download_button("Download table", csv, "file.csv", "text/csv", key='download-csv')
423
 
424
  return df
425
 
@@ -447,7 +447,7 @@ class TableExtractionPipeline():
447
  self.plot_results_detection(c1, model, image, probas, bboxes_scaled, delta_xmin, delta_ymin, delta_xmax, delta_ymax)
448
  cropped_img_list = self.crop_tables(image, probas, bboxes_scaled, delta_xmin, delta_ymin, delta_xmax, delta_ymax)
449
 
450
- for unpadded_table in cropped_img_list:
451
 
452
  table = self.add_padding(unpadded_table, padd_top, padd_right, padd_bottom, padd_left)
453
  # table = super_res(table)
@@ -477,7 +477,7 @@ class TableExtractionPipeline():
477
  cells_pytess_result = await asyncio.gather(*sequential_cell_img_list)
478
 
479
 
480
- self.create_dataframe(c3, cells_pytess_result, max_cols, max_rows)
481
  st.write('Errors in OCR is due to either quality of the image or performance of the OCR')
482
  # except:
483
  # st.write('Either incorrectly identified table or no table, to debug remove try/except')
381
  return df.to_csv().encode('utf-8')
382
 
383
 
384
+ def create_dataframe(self, c3, cells_pytess_result:list, max_cols:int, max_rows:int, table_num: int):
385
  '''Create dataframe using list of cell values of the table, also checks for valid header of dataframe
386
  Args:
387
  cells_pytess_result: list of strings, each element representing a cell in a table
419
 
420
  c3.dataframe(df)
421
  csv = self.convert_df(df)
422
+ c3.download_button("Download table", csv, "file.csv", "text/csv", key=f'download-csv-{table_num}')
423
 
424
  return df
425
 
447
  self.plot_results_detection(c1, model, image, probas, bboxes_scaled, delta_xmin, delta_ymin, delta_xmax, delta_ymax)
448
  cropped_img_list = self.crop_tables(image, probas, bboxes_scaled, delta_xmin, delta_ymin, delta_xmax, delta_ymax)
449
 
450
+ for table_num, unpadded_table in enumerate(cropped_img_list):
451
 
452
  table = self.add_padding(unpadded_table, padd_top, padd_right, padd_bottom, padd_left)
453
  # table = super_res(table)
477
  cells_pytess_result = await asyncio.gather(*sequential_cell_img_list)
478
 
479
 
480
+ self.create_dataframe(c3, cells_pytess_result, max_cols, max_rows, table_num)
481
  st.write('Errors in OCR is due to either quality of the image or performance of the OCR')
482
  # except:
483
  # st.write('Either incorrectly identified table or no table, to debug remove try/except')