duongthienz commited on
Commit
7c9a854
·
verified ·
1 Parent(s): 124995b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -286,11 +286,17 @@ def updateMultiSelect():
286
  if result:
287
  currAnnotation, _ = result
288
  speakerNames = list(currAnnotation.labels())
 
 
 
 
289
  raw_to_display = {}
290
  for sp in speakerNames:
291
  wk = f"rename_{fileName}_{sp}"
292
- live = st.session_state.get(wk, "").strip()
293
- raw_to_display[sp] = live if live else sp
 
 
294
  for i, category in enumerate(st.session_state['categories']):
295
  raw_choices = st.session_state['categorySelect'][fileName][i]
296
  st.session_state[f'multiselect_{category}'] = [raw_to_display.get(sp, sp) for sp in raw_choices]
@@ -773,7 +779,8 @@ try:
773
  current_renames = st.session_state.speakerRenames[currFile]
774
  for sp in speakerNames:
775
  widget_key = f"rename_{currFile}_{sp}"
776
- # Seed the widget state once; never pass value= so reruns don't overwrite it
 
777
  if widget_key not in st.session_state:
778
  st.session_state[widget_key] = current_renames.get(sp, "")
779
  live_name = st.session_state[widget_key].strip()
 
286
  if result:
287
  currAnnotation, _ = result
288
  speakerNames = list(currAnnotation.labels())
289
+
290
+ # Always restore rename widgets from the persistent speakerRenames dict
291
+ # so that coming back to a file after visiting another shows saved names.
292
+ saved_renames = st.session_state.speakerRenames.get(fileName, {})
293
  raw_to_display = {}
294
  for sp in speakerNames:
295
  wk = f"rename_{fileName}_{sp}"
296
+ saved = saved_renames.get(sp, "")
297
+ st.session_state[wk] = saved # unconditionally restore
298
+ raw_to_display[sp] = saved if saved else sp
299
+
300
  for i, category in enumerate(st.session_state['categories']):
301
  raw_choices = st.session_state['categorySelect'][fileName][i]
302
  st.session_state[f'multiselect_{category}'] = [raw_to_display.get(sp, sp) for sp in raw_choices]
 
779
  current_renames = st.session_state.speakerRenames[currFile]
780
  for sp in speakerNames:
781
  widget_key = f"rename_{currFile}_{sp}"
782
+ # Seed the widget state on first render only; updateMultiSelect handles
783
+ # restoring it unconditionally whenever the user switches files.
784
  if widget_key not in st.session_state:
785
  st.session_state[widget_key] = current_renames.get(sp, "")
786
  live_name = st.session_state[widget_key].strip()