Skip to content

Commit 31ad994

Browse files
committed
Confirm bug fix matches the one from data-saving branch, table dataframes are loaded only the first time program runs and does not get reinitialized at every streamlit rerun
1 parent e58b36a commit 31ad994

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

app_doctr.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ def authenticate():
353353
# Once images are uploaded
354354
if len(tally_sheet_images) > 0:
355355

356+
# First load session state
357+
if 'first_load' not in st.session_state:
358+
st.session_state['first_load'] = True
359+
356360
# Removing the data upload file button to force users to clear form
357361
upload_holder.empty()
358362

@@ -366,7 +370,9 @@ def authenticate():
366370
if 'page_nums' in st.session_state:
367371
del st.session_state['page_nums']
368372
if 'pages_confirmed' in st.session_state:
369-
del st.session_state['pages_confirmed']
373+
del st.session_state['pages_confirmed']
374+
if 'first_load' in st.session_state:
375+
del st.session_state['first_load']
370376
st.rerun()
371377

372378
# Sidebar for header data
@@ -435,14 +441,17 @@ def authenticate():
435441

436442
# Spinner for data upload. If it's going to be on screen for long, make it bespoke
437443
with st.spinner("Running image recognition..."):
438-
table_dfs, page_nums_to_display = [], []
439-
for i, sheet in enumerate(tally_sheet_images):
440-
img = Image(src=sheet)
441-
table_df = get_tabular_content_wrapper(doctr_ocr, img)
442-
table_dfs.extend(table_df)
443-
page_nums_to_display.extend([str(i + 1)] * len(table_df))
444-
table_dfs = clean_up(table_dfs)
445-
table_dfs = evaluate_cells(table_dfs)
444+
if st.session_state['first_load']:
445+
table_dfs, page_nums_to_display = [], []
446+
for i, sheet in enumerate(tally_sheet_images):
447+
img = Image(src=sheet)
448+
table_df = get_tabular_content_wrapper(doctr_ocr, img)
449+
table_dfs.extend(table_df)
450+
page_nums_to_display.extend([str(i + 1)] * len(table_df))
451+
table_dfs = clean_up(table_dfs)
452+
table_dfs = evaluate_cells(table_dfs)
453+
else:
454+
table_dfs = st.session_state['table_dfs'].copy()
446455

447456

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

0 commit comments

Comments
 (0)