Spaces:
Sleeping
Sleeping
Add autofill function to edit
Browse files
ui.py
CHANGED
|
@@ -145,16 +145,19 @@ 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 table: Speaker (with inline
|
| 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:
|
| 154 |
if "inline_rename_active" not in st.session_state:
|
| 155 |
-
st.session_state.inline_rename_active = {}
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
# Header
|
| 158 |
header_cols = st.columns([3, 3, 1])
|
| 159 |
header_cols[0].markdown("**Speaker**")
|
| 160 |
header_cols[1].markdown("**Audio Sample**")
|
|
@@ -173,22 +176,28 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 173 |
|
| 174 |
# --- Speaker cell ---
|
| 175 |
if is_editing:
|
| 176 |
-
|
| 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=
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 192 |
st.session_state.inline_rename_active[edit_key] = False
|
| 193 |
st.rerun()
|
| 194 |
if btn_col2.button("β", key=cancel_key, help="Cancel"):
|
|
@@ -199,7 +208,7 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 199 |
name_col, pencil_col = st.columns([4, 1])
|
| 200 |
name_col.write(display_name)
|
| 201 |
if pencil_col.button(
|
| 202 |
-
"
|
| 203 |
help=f"Rename {sp}",
|
| 204 |
):
|
| 205 |
st.session_state.inline_rename_active[edit_key] = True
|
|
@@ -211,7 +220,7 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 211 |
sp_segs = st.session_state.speakerSegments.get(currFile, {}).get(sp, [])
|
| 212 |
if has_waveform and sp_segs:
|
| 213 |
if row_cols[2].button(
|
| 214 |
-
"
|
| 215 |
help="Try a different audio sample for this speaker",
|
| 216 |
):
|
| 217 |
randomize_speaker_clip(currFile, sp)
|
|
|
|
| 145 |
# ---------------------------------------------------------------------------
|
| 146 |
|
| 147 |
def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
| 148 |
+
"""Render a table: Speaker (with inline β rename + autofill) | 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: {(currFile, sp): True}
|
| 154 |
if "inline_rename_active" not in st.session_state:
|
| 155 |
+
st.session_state.inline_rename_active = {}
|
| 156 |
+
# Last confirmed name β used as autofill suggestion for the next rename
|
| 157 |
+
if "inline_rename_last" not in st.session_state:
|
| 158 |
+
st.session_state.inline_rename_last = ""
|
| 159 |
|
| 160 |
+
# Header
|
| 161 |
header_cols = st.columns([3, 3, 1])
|
| 162 |
header_cols[0].markdown("**Speaker**")
|
| 163 |
header_cols[1].markdown("**Audio Sample**")
|
|
|
|
| 176 |
|
| 177 |
# --- Speaker cell ---
|
| 178 |
if is_editing:
|
| 179 |
+
input_key = f"inline_rename_input_{currFile}_{sp}"
|
|
|
|
| 180 |
confirm_key = f"inline_rename_confirm_{currFile}_{sp}"
|
| 181 |
cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
|
| 182 |
|
| 183 |
+
# Autofill suggestion: prefer existing name, then last confirmed name
|
| 184 |
+
current_val = display_name if display_name != sp else ""
|
| 185 |
+
suggestion = current_val or st.session_state.inline_rename_last
|
| 186 |
+
|
| 187 |
with row_cols[0]:
|
| 188 |
new_name = st.text_input(
|
| 189 |
"Rename",
|
| 190 |
+
value=current_val,
|
| 191 |
key=input_key,
|
| 192 |
label_visibility="collapsed",
|
| 193 |
+
placeholder=suggestion or f"Rename {sp}β¦",
|
| 194 |
)
|
| 195 |
btn_col1, btn_col2 = st.columns(2)
|
| 196 |
if btn_col1.button("β", key=confirm_key, help="Confirm rename"):
|
| 197 |
+
confirmed = new_name.strip() or suggestion
|
| 198 |
+
apply_inline_rename(currFile, sp, confirmed)
|
| 199 |
+
if confirmed:
|
| 200 |
+
st.session_state.inline_rename_last = confirmed
|
| 201 |
st.session_state.inline_rename_active[edit_key] = False
|
| 202 |
st.rerun()
|
| 203 |
if btn_col2.button("β", key=cancel_key, help="Cancel"):
|
|
|
|
| 208 |
name_col, pencil_col = st.columns([4, 1])
|
| 209 |
name_col.write(display_name)
|
| 210 |
if pencil_col.button(
|
| 211 |
+
"β", key=f"inline_rename_edit_{currFile}_{sp}",
|
| 212 |
help=f"Rename {sp}",
|
| 213 |
):
|
| 214 |
st.session_state.inline_rename_active[edit_key] = True
|
|
|
|
| 220 |
sp_segs = st.session_state.speakerSegments.get(currFile, {}).get(sp, [])
|
| 221 |
if has_waveform and sp_segs:
|
| 222 |
if row_cols[2].button(
|
| 223 |
+
"βΊ", key=f"sample_randomize_{currFile}_{sp}",
|
| 224 |
help="Try a different audio sample for this speaker",
|
| 225 |
):
|
| 226 |
randomize_speaker_clip(currFile, sp)
|