Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update ui.py
Browse files
ui.py
CHANGED
|
@@ -175,17 +175,41 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 175 |
# --- Speaker cell ---
|
| 176 |
if is_editing:
|
| 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 |
history = st.session_state.inline_rename_history
|
| 182 |
current_val = display_name if display_name != sp else ""
|
| 183 |
|
| 184 |
-
# Seed initial value when first opening
|
| 185 |
if input_key not in st.session_state:
|
| 186 |
st.session_state[input_key] = current_val
|
| 187 |
|
|
|
|
|
|
|
| 188 |
with row_cols[0]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
new_name = st.text_input(
|
| 190 |
"Rename",
|
| 191 |
key=input_key,
|
|
@@ -193,20 +217,6 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 193 |
placeholder=f"Rename {sp}…",
|
| 194 |
)
|
| 195 |
|
| 196 |
-
# History pills — clicking one writes into the input key and reruns
|
| 197 |
-
if history:
|
| 198 |
-
st.caption("Quick fill:")
|
| 199 |
-
pill_cols = st.columns(min(len(history), 4))
|
| 200 |
-
for hi, past_name in enumerate(history):
|
| 201 |
-
col_idx = hi % 4
|
| 202 |
-
if pill_cols[col_idx].button(
|
| 203 |
-
past_name,
|
| 204 |
-
key=f"inline_fill_{currFile}_{sp}_{hi}",
|
| 205 |
-
use_container_width=True,
|
| 206 |
-
):
|
| 207 |
-
st.session_state[input_key] = past_name
|
| 208 |
-
st.rerun()
|
| 209 |
-
|
| 210 |
btn_col1, btn_col2 = st.columns(2)
|
| 211 |
if btn_col1.button("✓", key=confirm_key, help="Confirm rename"):
|
| 212 |
confirmed = new_name.strip()
|
|
@@ -216,10 +226,12 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
|
|
| 216 |
st.session_state.inline_rename_history.append(confirmed)
|
| 217 |
st.session_state.inline_rename_active[edit_key] = False
|
| 218 |
st.session_state.pop(input_key, None)
|
|
|
|
| 219 |
st.rerun()
|
| 220 |
if btn_col2.button("✕", key=cancel_key, help="Cancel"):
|
| 221 |
st.session_state.inline_rename_active[edit_key] = False
|
| 222 |
st.session_state.pop(input_key, None)
|
|
|
|
| 223 |
st.rerun()
|
| 224 |
else:
|
| 225 |
with row_cols[0]:
|
|
|
|
| 175 |
# --- Speaker cell ---
|
| 176 |
if is_editing:
|
| 177 |
input_key = f"inline_rename_input_{currFile}_{sp}"
|
| 178 |
+
select_key = f"inline_rename_select_{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 |
+
# Seed initial text input value when first opening
|
| 186 |
if input_key not in st.session_state:
|
| 187 |
st.session_state[input_key] = current_val
|
| 188 |
|
| 189 |
+
_NEW_NAME_SENTINEL = "✏️ Type a new name…"
|
| 190 |
+
|
| 191 |
with row_cols[0]:
|
| 192 |
+
if history:
|
| 193 |
+
# Selectbox: existing history names + sentinel for "new"
|
| 194 |
+
dropdown_options = history + [_NEW_NAME_SENTINEL]
|
| 195 |
+
# Pre-select current value if it's already in history, else sentinel
|
| 196 |
+
default_idx = (
|
| 197 |
+
history.index(current_val)
|
| 198 |
+
if current_val in history
|
| 199 |
+
else len(dropdown_options) - 1
|
| 200 |
+
)
|
| 201 |
+
selected = st.selectbox(
|
| 202 |
+
"Pick or type",
|
| 203 |
+
options=dropdown_options,
|
| 204 |
+
index=default_idx,
|
| 205 |
+
key=select_key,
|
| 206 |
+
label_visibility="collapsed",
|
| 207 |
+
)
|
| 208 |
+
# If user picked an existing name, mirror it into the text input
|
| 209 |
+
if selected != _NEW_NAME_SENTINEL:
|
| 210 |
+
st.session_state[input_key] = selected
|
| 211 |
+
|
| 212 |
+
# Always show the text input so the user can freely edit/type
|
| 213 |
new_name = st.text_input(
|
| 214 |
"Rename",
|
| 215 |
key=input_key,
|
|
|
|
| 217 |
placeholder=f"Rename {sp}…",
|
| 218 |
)
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
btn_col1, btn_col2 = st.columns(2)
|
| 221 |
if btn_col1.button("✓", key=confirm_key, help="Confirm rename"):
|
| 222 |
confirmed = new_name.strip()
|
|
|
|
| 226 |
st.session_state.inline_rename_history.append(confirmed)
|
| 227 |
st.session_state.inline_rename_active[edit_key] = False
|
| 228 |
st.session_state.pop(input_key, None)
|
| 229 |
+
st.session_state.pop(select_key, None)
|
| 230 |
st.rerun()
|
| 231 |
if btn_col2.button("✕", key=cancel_key, help="Cancel"):
|
| 232 |
st.session_state.inline_rename_active[edit_key] = False
|
| 233 |
st.session_state.pop(input_key, None)
|
| 234 |
+
st.session_state.pop(select_key, None)
|
| 235 |
st.rerun()
|
| 236 |
else:
|
| 237 |
with row_cols[0]:
|