emvecchi commited on
Commit
801adb6
·
verified ·
1 Parent(s): 0f8c276

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -682,15 +682,33 @@ def iter_all_input_fields():
682
 
683
 
684
  def prep_and_save_data(index, skip_sample, completed: bool):
 
 
 
 
 
 
685
  payload = {
 
 
686
  'user_id': st.session_state.user_id,
687
  'index': st.session_state.current_index,
688
- **(st.session_state.data.iloc[index][COLS_TO_SAVE].to_dict() if 0 <= index < len(st.session_state.data) else {}),
689
- **{k: st.session_state[k + str(index)] for k in st.session_state.data_inputs_keys},
690
  'skip': skip_sample,
691
  'completed': int(completed),
692
  }
693
-
 
 
 
 
 
 
 
 
 
 
 
 
694
  for f in iter_all_input_fields():
695
  key = f.name + str(index)
696
  val = st.session_state.get(key, INPUT_FIELD_DEFAULT_VALUES[f.type])
@@ -822,9 +840,8 @@ elif st.session_state.current_index < len(st.session_state.data):
822
  show_fields(STEPS[step])
823
 
824
  c1, c2, c3 = st.columns([1,5,2])
825
- with c1:
826
- if st.button("<< Previous"):
827
- navigate(-1)
828
  # if step > 0:
829
  # st.session_state.step -= 1
830
  # st.rerun()
 
682
 
683
 
684
  def prep_and_save_data(index, skip_sample, completed: bool):
685
+ existing = read_saved_data() or {}
686
+
687
+ base = {}
688
+ if 0 <= index < len(st.session_state.data):
689
+ base = st.session_state.data.iloc[index][COLS_TO_SAVE].to_dict()
690
+
691
  payload = {
692
+ **existing, # previously saved stuff (extra keys, old schema, etc.)
693
+ **base,
694
  'user_id': st.session_state.user_id,
695
  'index': st.session_state.current_index,
 
 
696
  'skip': skip_sample,
697
  'completed': int(completed),
698
  }
699
+ # payload = {
700
+ # 'user_id': st.session_state.user_id,
701
+ # 'index': st.session_state.current_index,
702
+ # **(st.session_state.data.iloc[index][COLS_TO_SAVE].to_dict() if 0 <= index < len(st.session_state.data) else {}),
703
+ # **{k: st.session_state[k + str(index)] for k in st.session_state.data_inputs_keys},
704
+ # 'skip': skip_sample,
705
+ # 'completed': int(completed),
706
+ # }
707
+ for k in st.session_state.data_inputs_keys:
708
+ key = k + str(index)
709
+ if key in st.session_state:
710
+ payload[k] = st.session_state[key]
711
+
712
  for f in iter_all_input_fields():
713
  key = f.name + str(index)
714
  val = st.session_state.get(key, INPUT_FIELD_DEFAULT_VALUES[f.type])
 
840
  show_fields(STEPS[step])
841
 
842
  c1, c2, c3 = st.columns([1,5,2])
843
+ # with c1:
844
+ # if st.button("<< Previous"):
 
845
  # if step > 0:
846
  # st.session_state.step -= 1
847
  # st.rerun()