Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
add role column in rename speaker tab
Browse files
ui.py
CHANGED
|
@@ -220,11 +220,20 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 220 |
if entry["name"] not in st.session_state.inline_rename_history:
|
| 221 |
st.session_state.inline_rename_history.append(entry["name"])
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
# Header
|
| 224 |
-
header_cols = st.columns([3,
|
| 225 |
header_cols[0].markdown("**Speaker**")
|
| 226 |
-
header_cols[1].markdown("**
|
| 227 |
-
header_cols[2].markdown("**
|
|
|
|
| 228 |
st.markdown("<hr style='margin-top:2px; margin-bottom:4px;'>", unsafe_allow_html=True)
|
| 229 |
|
| 230 |
if not has_samples:
|
|
@@ -235,7 +244,7 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 235 |
edit_key = (currFile, sp)
|
| 236 |
is_editing = st.session_state.inline_rename_active.get(edit_key, False)
|
| 237 |
|
| 238 |
-
row_cols = st.columns([3,
|
| 239 |
|
| 240 |
# --- Speaker cell ---
|
| 241 |
if is_editing:
|
|
@@ -252,21 +261,6 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 252 |
_NEW_OPTION = "οΌ Enter a new name"
|
| 253 |
|
| 254 |
with row_cols[0]:
|
| 255 |
-
# Wrap in a form so pressing Enter submits (confirms) the rename.
|
| 256 |
-
# Change the default "Press Enter to submit form" helper text via CSS.
|
| 257 |
-
st.markdown(
|
| 258 |
-
"<style>"
|
| 259 |
-
# target the small helper text Streamlit injects into every form
|
| 260 |
-
"div[data-testid='stForm'] small {"
|
| 261 |
-
" visibility: hidden;" # hide original text β¦
|
| 262 |
-
"}"
|
| 263 |
-
"div[data-testid='stForm'] small::after {"
|
| 264 |
-
" content: 'Press Enter to apply';"
|
| 265 |
-
" visibility: visible;"
|
| 266 |
-
"}"
|
| 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
|
|
@@ -298,6 +292,25 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 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
|
|
@@ -318,6 +331,14 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 318 |
placeholder=f"Rename {sp}β¦",
|
| 319 |
)
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
_, btn_col1, btn_col2, btn_col3 = st.columns([4, 1, 1, 1])
|
| 322 |
confirmed_submit = btn_col1.form_submit_button("β", help="Confirm rename (or press Enter)")
|
| 323 |
cancel_clicked = btn_col2.form_submit_button("β", help="Cancel")
|
|
@@ -354,19 +375,22 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 354 |
st.session_state.inline_rename_active[edit_key] = True
|
| 355 |
st.rerun()
|
| 356 |
|
|
|
|
|
|
|
|
|
|
| 357 |
# --- Audio sample cell ---
|
| 358 |
if sp in file_samples:
|
| 359 |
-
row_cols[
|
| 360 |
sp_segs = st.session_state.speakerSegments.get(currFile, {}).get(sp, [])
|
| 361 |
if has_waveform and sp_segs:
|
| 362 |
-
if row_cols[
|
| 363 |
"βΊ", key=f"sample_randomize_{currFile}_{sp}",
|
| 364 |
help="Try a different audio sample for this speaker",
|
| 365 |
):
|
| 366 |
randomize_speaker_clip(currFile, sp)
|
| 367 |
st.rerun()
|
| 368 |
else:
|
| 369 |
-
row_cols[
|
| 370 |
|
| 371 |
|
| 372 |
# ---------------------------------------------------------------------------
|
|
|
|
| 220 |
if entry["name"] not in st.session_state.inline_rename_history:
|
| 221 |
st.session_state.inline_rename_history.append(entry["name"])
|
| 222 |
|
| 223 |
+
def _get_role(sp):
|
| 224 |
+
"""Return the role name assigned to this speaker, or empty string."""
|
| 225 |
+
token = f"{currFile}: {sp}"
|
| 226 |
+
for i, tokens in enumerate(st.session_state.categorySelect):
|
| 227 |
+
if token in tokens:
|
| 228 |
+
return st.session_state.categories[i]
|
| 229 |
+
return ""
|
| 230 |
+
|
| 231 |
# Header
|
| 232 |
+
header_cols = st.columns([3, 2, 2, 1])
|
| 233 |
header_cols[0].markdown("**Speaker**")
|
| 234 |
+
header_cols[1].markdown("**Role**")
|
| 235 |
+
header_cols[2].markdown("**Audio Sample**")
|
| 236 |
+
header_cols[3].markdown("** **", unsafe_allow_html=True)
|
| 237 |
st.markdown("<hr style='margin-top:2px; margin-bottom:4px;'>", unsafe_allow_html=True)
|
| 238 |
|
| 239 |
if not has_samples:
|
|
|
|
| 244 |
edit_key = (currFile, sp)
|
| 245 |
is_editing = st.session_state.inline_rename_active.get(edit_key, False)
|
| 246 |
|
| 247 |
+
row_cols = st.columns([3, 2, 2, 1])
|
| 248 |
|
| 249 |
# --- Speaker cell ---
|
| 250 |
if is_editing:
|
|
|
|
| 261 |
_NEW_OPTION = "οΌ Enter a new name"
|
| 262 |
|
| 263 |
with row_cols[0]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
# The selectbox MUST live outside the form: inside a form,
|
| 265 |
# widget state is only committed on submit, so choosing
|
| 266 |
# _NEW_OPTION would never make the text input appear until
|
|
|
|
| 292 |
if not show_input:
|
| 293 |
new_name = chosen
|
| 294 |
|
| 295 |
+
# Hide Streamlit's built-in "Press Enter to submit form" hint
|
| 296 |
+
# and replace it. Targets both <small> (older Streamlit) and
|
| 297 |
+
# <p> (newer Streamlit). font-size:0 collapses the original;
|
| 298 |
+
# ::after injects the replacement.
|
| 299 |
+
st.markdown(
|
| 300 |
+
"<style>"
|
| 301 |
+
"div[data-testid='stForm'] small,"
|
| 302 |
+
"div[data-testid='stForm'] p:last-of-type {"
|
| 303 |
+
" font-size: 0 !important;"
|
| 304 |
+
"}"
|
| 305 |
+
"div[data-testid='stForm'] small::after,"
|
| 306 |
+
"div[data-testid='stForm'] p:last-of-type::after {"
|
| 307 |
+
" content: 'Press Enter to apply';"
|
| 308 |
+
" font-size: 0.8rem;"
|
| 309 |
+
" color: gray;"
|
| 310 |
+
"}"
|
| 311 |
+
"</style>",
|
| 312 |
+
unsafe_allow_html=True,
|
| 313 |
+
)
|
| 314 |
with st.form(key=form_key, border=False):
|
| 315 |
if not history:
|
| 316 |
# No history β plain text input is the only field
|
|
|
|
| 331 |
placeholder=f"Rename {sp}β¦",
|
| 332 |
)
|
| 333 |
|
| 334 |
+
# A disabled first submit button suppresses Streamlit's
|
| 335 |
+
# "Press Enter to submit form" hint (built-in behaviour)
|
| 336 |
+
# while still allowing Enter to submit via the real buttons.
|
| 337 |
+
st.form_submit_button(
|
| 338 |
+
"", disabled=True,
|
| 339 |
+
help=None,
|
| 340 |
+
label_visibility="collapsed",
|
| 341 |
+
)
|
| 342 |
_, btn_col1, btn_col2, btn_col3 = st.columns([4, 1, 1, 1])
|
| 343 |
confirmed_submit = btn_col1.form_submit_button("β", help="Confirm rename (or press Enter)")
|
| 344 |
cancel_clicked = btn_col2.form_submit_button("β", help="Cancel")
|
|
|
|
| 375 |
st.session_state.inline_rename_active[edit_key] = True
|
| 376 |
st.rerun()
|
| 377 |
|
| 378 |
+
# --- Role cell ---
|
| 379 |
+
row_cols[1].write(_get_role(sp))
|
| 380 |
+
|
| 381 |
# --- Audio sample cell ---
|
| 382 |
if sp in file_samples:
|
| 383 |
+
row_cols[2].audio(file_samples[sp], format="audio/wav")
|
| 384 |
sp_segs = st.session_state.speakerSegments.get(currFile, {}).get(sp, [])
|
| 385 |
if has_waveform and sp_segs:
|
| 386 |
+
if row_cols[3].button(
|
| 387 |
"βΊ", key=f"sample_randomize_{currFile}_{sp}",
|
| 388 |
help="Try a different audio sample for this speaker",
|
| 389 |
):
|
| 390 |
randomize_speaker_clip(currFile, sp)
|
| 391 |
st.rerun()
|
| 392 |
else:
|
| 393 |
+
row_cols[2].write("β")
|
| 394 |
|
| 395 |
|
| 396 |
# ---------------------------------------------------------------------------
|