Spaces:
Sleeping
Sleeping
Add pencil edit to Rename Speaker
Browse files
ui.py
CHANGED
|
@@ -14,7 +14,7 @@ import utils
|
|
| 14 |
from state import (
|
| 15 |
updateCategoryOptions, removeCategory, addCategory,
|
| 16 |
applyGlobalRenames, addGlobalRename, removeGlobalRename,
|
| 17 |
-
_global_rename_key, randomize_speaker_clip,
|
| 18 |
)
|
| 19 |
|
| 20 |
|
|
@@ -145,13 +145,17 @@ def render_data_table(tableDF, speakerNames, raw_to_display, currFile):
|
|
| 145 |
# ---------------------------------------------------------------------------
|
| 146 |
|
| 147 |
def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
| 148 |
-
"""Render a
|
| 149 |
-
file_samples
|
| 150 |
-
has_waveform
|
| 151 |
-
has_samples
|
| 152 |
|
| 153 |
-
#
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
header_cols[0].markdown("**Speaker**")
|
| 156 |
header_cols[1].markdown("**Audio Sample**")
|
| 157 |
header_cols[2].markdown("** **", unsafe_allow_html=True)
|
|
@@ -159,12 +163,49 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 159 |
|
| 160 |
if not has_samples:
|
| 161 |
st.info("Audio samples are only available for files analyzed from audio (not RTTM/CSV/TXT).")
|
| 162 |
-
return
|
| 163 |
|
| 164 |
for sp in speakerNames:
|
| 165 |
display_name = raw_to_display.get(sp, sp)
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
if sp in file_samples:
|
| 169 |
row_cols[1].audio(file_samples[sp], format="audio/wav")
|
| 170 |
sp_segs = st.session_state.speakerSegments.get(currFile, {}).get(sp, [])
|
|
|
|
| 14 |
from state import (
|
| 15 |
updateCategoryOptions, removeCategory, addCategory,
|
| 16 |
applyGlobalRenames, addGlobalRename, removeGlobalRename,
|
| 17 |
+
_global_rename_key, randomize_speaker_clip, apply_inline_rename,
|
| 18 |
)
|
| 19 |
|
| 20 |
|
|
|
|
| 145 |
# ---------------------------------------------------------------------------
|
| 146 |
|
| 147 |
def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
| 148 |
+
"""Render a table: Speaker (with inline ✏️ rename) | Audio Sample | 🔀 button."""
|
| 149 |
+
file_samples = st.session_state.speakerClips.get(currFile, {})
|
| 150 |
+
has_waveform = currFile in st.session_state.speakerWaveforms
|
| 151 |
+
has_samples = bool(file_samples)
|
| 152 |
|
| 153 |
+
# Per-speaker editing toggle: set by clicking ✏️, cleared on confirm/cancel
|
| 154 |
+
if "inline_rename_active" not in st.session_state:
|
| 155 |
+
st.session_state.inline_rename_active = {} # {(currFile, sp): True}
|
| 156 |
+
|
| 157 |
+
# Header — widths: [name+pencil | audio | randomize]
|
| 158 |
+
header_cols = st.columns([3, 3, 1])
|
| 159 |
header_cols[0].markdown("**Speaker**")
|
| 160 |
header_cols[1].markdown("**Audio Sample**")
|
| 161 |
header_cols[2].markdown("** **", unsafe_allow_html=True)
|
|
|
|
| 163 |
|
| 164 |
if not has_samples:
|
| 165 |
st.info("Audio samples are only available for files analyzed from audio (not RTTM/CSV/TXT).")
|
|
|
|
| 166 |
|
| 167 |
for sp in speakerNames:
|
| 168 |
display_name = raw_to_display.get(sp, sp)
|
| 169 |
+
edit_key = (currFile, sp)
|
| 170 |
+
is_editing = st.session_state.inline_rename_active.get(edit_key, False)
|
| 171 |
+
|
| 172 |
+
row_cols = st.columns([3, 3, 1])
|
| 173 |
+
|
| 174 |
+
# --- Speaker cell ---
|
| 175 |
+
if is_editing:
|
| 176 |
+
# Text input + confirm/cancel inline
|
| 177 |
+
input_key = f"inline_rename_input_{currFile}_{sp}"
|
| 178 |
+
confirm_key = f"inline_rename_confirm_{currFile}_{sp}"
|
| 179 |
+
cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
|
| 180 |
+
|
| 181 |
+
with row_cols[0]:
|
| 182 |
+
new_name = st.text_input(
|
| 183 |
+
"Rename",
|
| 184 |
+
value=display_name if display_name != sp else "",
|
| 185 |
+
key=input_key,
|
| 186 |
+
label_visibility="collapsed",
|
| 187 |
+
placeholder=f"Rename {sp}…",
|
| 188 |
+
)
|
| 189 |
+
btn_col1, btn_col2 = st.columns(2)
|
| 190 |
+
if btn_col1.button("✓", key=confirm_key, help="Confirm rename"):
|
| 191 |
+
apply_inline_rename(currFile, sp, new_name)
|
| 192 |
+
st.session_state.inline_rename_active[edit_key] = False
|
| 193 |
+
st.rerun()
|
| 194 |
+
if btn_col2.button("✕", key=cancel_key, help="Cancel"):
|
| 195 |
+
st.session_state.inline_rename_active[edit_key] = False
|
| 196 |
+
st.rerun()
|
| 197 |
+
else:
|
| 198 |
+
with row_cols[0]:
|
| 199 |
+
name_col, pencil_col = st.columns([4, 1])
|
| 200 |
+
name_col.write(display_name)
|
| 201 |
+
if pencil_col.button(
|
| 202 |
+
"✏️", key=f"inline_rename_edit_{currFile}_{sp}",
|
| 203 |
+
help=f"Rename {sp}",
|
| 204 |
+
):
|
| 205 |
+
st.session_state.inline_rename_active[edit_key] = True
|
| 206 |
+
st.rerun()
|
| 207 |
+
|
| 208 |
+
# --- Audio sample cell ---
|
| 209 |
if sp in file_samples:
|
| 210 |
row_cols[1].audio(file_samples[sp], format="audio/wav")
|
| 211 |
sp_segs = st.session_state.speakerSegments.get(currFile, {}).get(sp, [])
|