duongthienz commited on
Commit
de3bbf7
·
verified ·
1 Parent(s): ab336e6

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +15 -1
ui.py CHANGED
@@ -202,8 +202,15 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
202
 
203
  if "inline_rename_active" not in st.session_state:
204
  st.session_state.inline_rename_active = {}
 
 
 
 
205
  if "inline_rename_history" not in st.session_state:
206
  st.session_state.inline_rename_history = []
 
 
 
207
 
208
  # Header
209
  header_cols = st.columns([3, 3, 1])
@@ -230,7 +237,10 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
230
  cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
231
 
232
  history = st.session_state.inline_rename_history
233
- current_val = display_name if display_name != sp else ""
 
 
 
234
 
235
  _NEW_OPTION = "+ Enter a new name"
236
 
@@ -280,6 +290,10 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
280
  apply_inline_rename(currFile, sp, confirmed)
281
  if confirmed not in st.session_state.inline_rename_history:
282
  st.session_state.inline_rename_history.append(confirmed)
 
 
 
 
283
  st.session_state.inline_rename_active[edit_key] = False
284
  st.session_state.pop(select_key, None)
285
  st.session_state.pop(input_key, None)
 
202
 
203
  if "inline_rename_active" not in st.session_state:
204
  st.session_state.inline_rename_active = {}
205
+
206
+ # Build the history list from all confirmed names: start from whatever was
207
+ # saved from past sessions, then merge in any names already in globalRenames
208
+ # so that sidebar-added names show up as history options in the tab too.
209
  if "inline_rename_history" not in st.session_state:
210
  st.session_state.inline_rename_history = []
211
+ for entry in st.session_state.globalRenames:
212
+ if entry["name"] not in st.session_state.inline_rename_history:
213
+ st.session_state.inline_rename_history.append(entry["name"])
214
 
215
  # Header
216
  header_cols = st.columns([3, 3, 1])
 
237
  cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
238
 
239
  history = st.session_state.inline_rename_history
240
+ # Read the saved rename directly from speakerRenames so that
241
+ # current_val is "" when no rename exists, even if display_name
242
+ # happens to equal the raw speaker label for some other reason.
243
+ current_val = st.session_state.speakerRenames.get(currFile, {}).get(sp, "")
244
 
245
  _NEW_OPTION = "+ Enter a new name"
246
 
 
290
  apply_inline_rename(currFile, sp, confirmed)
291
  if confirmed not in st.session_state.inline_rename_history:
292
  st.session_state.inline_rename_history.append(confirmed)
293
+ else:
294
+ # Empty name = revert this speaker back to SPEAKER_##
295
+ apply_inline_rename(currFile, sp, "")
296
+ st.toast(f"Reverted {sp} to original label")
297
  st.session_state.inline_rename_active[edit_key] = False
298
  st.session_state.pop(select_key, None)
299
  st.session_state.pop(input_key, None)