Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update ui.py
Browse files
ui.py
CHANGED
|
@@ -267,41 +267,52 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 267 |
"</style>",
|
| 268 |
unsafe_allow_html=True,
|
| 269 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
with st.form(key=form_key, border=False):
|
| 271 |
-
if history:
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
history.index(current_val) if current_val in history
|
| 275 |
-
else len(options) - 1
|
| 276 |
-
)
|
| 277 |
-
st.selectbox(
|
| 278 |
"Rename",
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
key=select_key,
|
| 282 |
label_visibility="collapsed",
|
|
|
|
| 283 |
)
|
| 284 |
-
|
| 285 |
-
#
|
| 286 |
-
# even though st.selectbox() inside a form returns the
|
| 287 |
-
# previous-run value until the form is submitted.
|
| 288 |
-
chosen = st.session_state.get(select_key, options[default_idx])
|
| 289 |
-
if chosen == _NEW_OPTION:
|
| 290 |
-
new_name = st.text_input(
|
| 291 |
-
"New name",
|
| 292 |
-
value="",
|
| 293 |
-
key=input_key,
|
| 294 |
-
label_visibility="collapsed",
|
| 295 |
-
placeholder=f"Rename {sp}β¦",
|
| 296 |
-
)
|
| 297 |
-
else:
|
| 298 |
-
new_name = chosen
|
| 299 |
-
st.session_state.pop(input_key, None)
|
| 300 |
-
else:
|
| 301 |
-
# No history yet β just a plain text input
|
| 302 |
new_name = st.text_input(
|
| 303 |
-
"
|
| 304 |
-
value=
|
| 305 |
key=input_key,
|
| 306 |
label_visibility="collapsed",
|
| 307 |
placeholder=f"Rename {sp}β¦",
|
|
@@ -312,27 +323,25 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 312 |
cancel_clicked = btn_col2.form_submit_button("β", help="Cancel")
|
| 313 |
reset_clicked = btn_col3.form_submit_button("β³", help="Reset to original speaker label")
|
| 314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
if confirmed_submit:
|
| 316 |
confirmed = (new_name or "").strip()
|
| 317 |
apply_inline_rename(currFile, sp, confirmed)
|
| 318 |
if confirmed and confirmed not in st.session_state.inline_rename_history:
|
| 319 |
st.session_state.inline_rename_history.append(confirmed)
|
| 320 |
-
|
| 321 |
-
st.session_state.pop(select_key, None)
|
| 322 |
-
st.session_state.pop(input_key, None)
|
| 323 |
st.rerun()
|
| 324 |
if cancel_clicked:
|
| 325 |
-
|
| 326 |
-
st.session_state.pop(select_key, None)
|
| 327 |
-
st.session_state.pop(input_key, None)
|
| 328 |
st.rerun()
|
| 329 |
if reset_clicked:
|
| 330 |
-
# Revert to raw speaker label β same as removing the token
|
| 331 |
-
# from a rename entry in the sidebar
|
| 332 |
apply_inline_rename(currFile, sp, "")
|
| 333 |
-
|
| 334 |
-
st.session_state.pop(select_key, None)
|
| 335 |
-
st.session_state.pop(input_key, None)
|
| 336 |
st.rerun()
|
| 337 |
else:
|
| 338 |
with row_cols[0]:
|
|
|
|
| 267 |
"</style>",
|
| 268 |
unsafe_allow_html=True,
|
| 269 |
)
|
| 270 |
+
# The selectbox MUST live outside the form: inside a form,
|
| 271 |
+
# widget state is only committed on submit, so choosing
|
| 272 |
+
# _NEW_OPTION would never make the text input appear until
|
| 273 |
+
# after an unrelated submit. We track the live choice in
|
| 274 |
+
# chosen_key and only put the text input + buttons in the form.
|
| 275 |
+
chosen_key = f"inline_rename_chosen_{currFile}_{sp}"
|
| 276 |
+
show_input = False
|
| 277 |
+
new_name = ""
|
| 278 |
+
|
| 279 |
+
if history:
|
| 280 |
+
options = history + [_NEW_OPTION]
|
| 281 |
+
default_idx = (
|
| 282 |
+
history.index(current_val) if current_val in history
|
| 283 |
+
else len(options) - 1
|
| 284 |
+
)
|
| 285 |
+
if chosen_key not in st.session_state:
|
| 286 |
+
st.session_state[chosen_key] = options[default_idx]
|
| 287 |
+
# Clamp stored value in case history changed
|
| 288 |
+
if st.session_state[chosen_key] not in options:
|
| 289 |
+
st.session_state[chosen_key] = options[default_idx]
|
| 290 |
+
st.selectbox(
|
| 291 |
+
"Rename",
|
| 292 |
+
options=options,
|
| 293 |
+
key=chosen_key,
|
| 294 |
+
label_visibility="collapsed",
|
| 295 |
+
)
|
| 296 |
+
chosen = st.session_state[chosen_key]
|
| 297 |
+
show_input = (chosen == _NEW_OPTION)
|
| 298 |
+
if not show_input:
|
| 299 |
+
new_name = chosen
|
| 300 |
+
|
| 301 |
with st.form(key=form_key, border=False):
|
| 302 |
+
if not history:
|
| 303 |
+
# No history β plain text input is the only field
|
| 304 |
+
new_name = st.text_input(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
"Rename",
|
| 306 |
+
value=current_val,
|
| 307 |
+
key=input_key,
|
|
|
|
| 308 |
label_visibility="collapsed",
|
| 309 |
+
placeholder=f"Rename {sp}β¦",
|
| 310 |
)
|
| 311 |
+
elif show_input:
|
| 312 |
+
# User picked "+ Enter a new name" β show free-text field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
new_name = st.text_input(
|
| 314 |
+
"New name",
|
| 315 |
+
value="",
|
| 316 |
key=input_key,
|
| 317 |
label_visibility="collapsed",
|
| 318 |
placeholder=f"Rename {sp}β¦",
|
|
|
|
| 323 |
cancel_clicked = btn_col2.form_submit_button("β", help="Cancel")
|
| 324 |
reset_clicked = btn_col3.form_submit_button("β³", help="Reset to original speaker label")
|
| 325 |
|
| 326 |
+
def _cleanup():
|
| 327 |
+
st.session_state.inline_rename_active[edit_key] = False
|
| 328 |
+
st.session_state.pop(select_key, None)
|
| 329 |
+
st.session_state.pop(chosen_key, None)
|
| 330 |
+
st.session_state.pop(input_key, None)
|
| 331 |
+
|
| 332 |
if confirmed_submit:
|
| 333 |
confirmed = (new_name or "").strip()
|
| 334 |
apply_inline_rename(currFile, sp, confirmed)
|
| 335 |
if confirmed and confirmed not in st.session_state.inline_rename_history:
|
| 336 |
st.session_state.inline_rename_history.append(confirmed)
|
| 337 |
+
_cleanup()
|
|
|
|
|
|
|
| 338 |
st.rerun()
|
| 339 |
if cancel_clicked:
|
| 340 |
+
_cleanup()
|
|
|
|
|
|
|
| 341 |
st.rerun()
|
| 342 |
if reset_clicked:
|
|
|
|
|
|
|
| 343 |
apply_inline_rename(currFile, sp, "")
|
| 344 |
+
_cleanup()
|
|
|
|
|
|
|
| 345 |
st.rerun()
|
| 346 |
else:
|
| 347 |
with row_cols[0]:
|