Skip to content

Commit 5cf3ffe

Browse files
committedAug 7, 2024
Removing the double entry bug + not saving when confirming
1 parent 77a29cb commit 5cf3ffe

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed
 

‎app_llm.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ def authenticate():
312312
# Once images are uploaded
313313
if len(tally_sheet_images) > 0:
314314

315+
# First load session state
316+
if 'first_load' not in st.session_state:
317+
st.session_state['first_load'] = True
318+
315319
# Removing the data upload file button to force users to clear form
316320
upload_holder.empty()
317321

@@ -326,6 +330,8 @@ def authenticate():
326330
del st.session_state['page_nums']
327331
if 'pages_confirmed' in st.session_state:
328332
del st.session_state['pages_confirmed']
333+
if 'first_load' in st.session_state:
334+
del st.session_state['first_load']
329335
st.rerun()
330336

331337
# Sidebar for header data
@@ -396,13 +402,17 @@ def authenticate():
396402

397403
# Populate streamlit with data recognized from tally sheets
398404

399-
table_names, table_dfs, page_nums_to_display = [], [], []
400-
for i, result in enumerate(results):
401-
names, df = parse_table_data_wrapper(result)
402-
table_names.extend(names)
403-
table_dfs.extend(df)
404-
page_nums_to_display.extend([str(i + 1)] * len(names))
405-
table_dfs = post_processing.evaluate_cells(table_dfs)
405+
if st.session_state['first_load']:
406+
table_names, table_dfs, page_nums_to_display = [], [], []
407+
for i, result in enumerate(results):
408+
names, df = parse_table_data_wrapper(result)
409+
table_names.extend(names)
410+
table_dfs.extend(df)
411+
page_nums_to_display.extend([str(i + 1)] * len(names))
412+
table_dfs = post_processing.evaluate_cells(table_dfs)
413+
st.session_state['first_load'] = False
414+
else:
415+
table_dfs = st.session_state['table_dfs'].copy()
406416

407417
# Form session state initialization
408418
if 'table_names' not in st.session_state:
@@ -465,6 +475,7 @@ def authenticate():
465475
# This can normalize table headers to match DHIS2 using Levenstein distance or semantic search
466476
if data_set_selected_id:
467477
edited_dfs = correct_field_names(table_dfs, form)
478+
print(edited_dfs)
468479
save_st_table(edited_dfs)
469480
else:
470481
raise Exception("Select a valid dataset")

0 commit comments

Comments
 (0)