Skip to content

Commit

Permalink
Confirm bug fix matches the one from data-saving branch, table datafr…
Browse files Browse the repository at this point in the history
…ames are loaded only the first time program runs and does not get reinitialized at every streamlit rerun
  • Loading branch information
anjus1313 committed Aug 9, 2024
1 parent e58b36a commit 31ad994
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions app_doctr.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ def authenticate():
# Once images are uploaded
if len(tally_sheet_images) > 0:

# First load session state
if 'first_load' not in st.session_state:
st.session_state['first_load'] = True

# Removing the data upload file button to force users to clear form
upload_holder.empty()

Expand All @@ -366,7 +370,9 @@ def authenticate():
if 'page_nums' in st.session_state:
del st.session_state['page_nums']
if 'pages_confirmed' in st.session_state:
del st.session_state['pages_confirmed']
del st.session_state['pages_confirmed']
if 'first_load' in st.session_state:
del st.session_state['first_load']
st.rerun()

# Sidebar for header data
Expand Down Expand Up @@ -435,14 +441,17 @@ def authenticate():

# Spinner for data upload. If it's going to be on screen for long, make it bespoke
with st.spinner("Running image recognition..."):
table_dfs, page_nums_to_display = [], []
for i, sheet in enumerate(tally_sheet_images):
img = Image(src=sheet)
table_df = get_tabular_content_wrapper(doctr_ocr, img)
table_dfs.extend(table_df)
page_nums_to_display.extend([str(i + 1)] * len(table_df))
table_dfs = clean_up(table_dfs)
table_dfs = evaluate_cells(table_dfs)
if st.session_state['first_load']:
table_dfs, page_nums_to_display = [], []
for i, sheet in enumerate(tally_sheet_images):
img = Image(src=sheet)
table_df = get_tabular_content_wrapper(doctr_ocr, img)
table_dfs.extend(table_df)
page_nums_to_display.extend([str(i + 1)] * len(table_df))
table_dfs = clean_up(table_dfs)
table_dfs = evaluate_cells(table_dfs)
else:
table_dfs = st.session_state['table_dfs'].copy()


# Form session state initialization
Expand Down Expand Up @@ -470,7 +479,6 @@ def authenticate():
# Uploading the tables, adding columns for each name
for i, (df, page_num) in enumerate(zip(st.session_state.table_dfs, st.session_state.page_nums)):
if page_num != page_selected:
table_dfs[i] = pd.DataFrame(df)
continue
int_page_num = int(page_num.replace(PAGE_REVIEWED_INDICATOR, "").strip())
st.write(f"Table {i + 1}")
Expand Down

0 comments on commit 31ad994

Please sign in to comment.