duongthienz commited on
Commit
2e2161f
·
verified ·
1 Parent(s): 8de474f

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +42 -11
ui.py CHANGED
@@ -175,24 +175,53 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
175
  # --- Speaker cell ---
176
  if is_editing:
177
  select_key = f"inline_rename_select_{currFile}_{sp}"
 
178
  confirm_key = f"inline_rename_confirm_{currFile}_{sp}"
179
  cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
180
 
181
  history = st.session_state.inline_rename_history
182
  current_val = display_name if display_name != sp else ""
183
 
 
 
184
  with row_cols[0]:
185
- # Single editable selectbox acts as a combobox:
186
- # user can pick a past name or type a brand-new one freely.
187
- new_name = st.selectbox(
188
- "Rename",
189
- options=history,
190
- index=history.index(current_val) if current_val in history else None,
191
- key=select_key,
192
- label_visibility="collapsed",
193
- placeholder=f"Rename {sp}…",
194
- editable=True,
195
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  btn_col1, btn_col2 = st.columns(2)
198
  if btn_col1.button("✓", key=confirm_key, help="Confirm rename"):
@@ -203,10 +232,12 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
203
  st.session_state.inline_rename_history.append(confirmed)
204
  st.session_state.inline_rename_active[edit_key] = False
205
  st.session_state.pop(select_key, None)
 
206
  st.rerun()
207
  if btn_col2.button("✕", key=cancel_key, help="Cancel"):
208
  st.session_state.inline_rename_active[edit_key] = False
209
  st.session_state.pop(select_key, None)
 
210
  st.rerun()
211
  else:
212
  with row_cols[0]:
 
175
  # --- Speaker cell ---
176
  if is_editing:
177
  select_key = f"inline_rename_select_{currFile}_{sp}"
178
+ input_key = f"inline_rename_input_{currFile}_{sp}"
179
  confirm_key = f"inline_rename_confirm_{currFile}_{sp}"
180
  cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
181
 
182
  history = st.session_state.inline_rename_history
183
  current_val = display_name if display_name != sp else ""
184
 
185
+ _NEW_OPTION = "+ Enter a new name"
186
+
187
  with row_cols[0]:
188
+ if history:
189
+ # Show dropdown of past names; last option triggers text input
190
+ options = history + [_NEW_OPTION]
191
+ default_idx = (
192
+ history.index(current_val) if current_val in history
193
+ else len(options) - 1
194
+ )
195
+ chosen = st.selectbox(
196
+ "Rename",
197
+ options=options,
198
+ index=default_idx,
199
+ key=select_key,
200
+ label_visibility="collapsed",
201
+ )
202
+ # Only show text input when user wants a brand-new name
203
+ if chosen == _NEW_OPTION:
204
+ if input_key not in st.session_state:
205
+ st.session_state[input_key] = ""
206
+ new_name = st.text_input(
207
+ "New name",
208
+ key=input_key,
209
+ label_visibility="collapsed",
210
+ placeholder=f"Rename {sp}…",
211
+ )
212
+ else:
213
+ new_name = chosen
214
+ st.session_state.pop(input_key, None)
215
+ else:
216
+ # No history yet — just a plain text input
217
+ if input_key not in st.session_state:
218
+ st.session_state[input_key] = current_val
219
+ new_name = st.text_input(
220
+ "Rename",
221
+ key=input_key,
222
+ label_visibility="collapsed",
223
+ placeholder=f"Rename {sp}…",
224
+ )
225
 
226
  btn_col1, btn_col2 = st.columns(2)
227
  if btn_col1.button("✓", key=confirm_key, help="Confirm rename"):
 
232
  st.session_state.inline_rename_history.append(confirmed)
233
  st.session_state.inline_rename_active[edit_key] = False
234
  st.session_state.pop(select_key, None)
235
+ st.session_state.pop(input_key, None)
236
  st.rerun()
237
  if btn_col2.button("✕", key=cancel_key, help="Cancel"):
238
  st.session_state.inline_rename_active[edit_key] = False
239
  st.session_state.pop(select_key, None)
240
+ st.session_state.pop(input_key, None)
241
  st.rerun()
242
  else:
243
  with row_cols[0]: