Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update state.py
Browse files
state.py
CHANGED
|
@@ -113,11 +113,16 @@ def updateCategoryOptions():
|
|
| 113 |
"""Store tokens ('fname: SPEAKER_##') in the global categorySelect lists."""
|
| 114 |
if st.session_state.resetResult:
|
| 115 |
return
|
| 116 |
-
# Rebuild
|
|
|
|
| 117 |
for i, category in enumerate(st.session_state.categories):
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
# Recompute unusedSpeakers for all files
|
| 122 |
all_assigned_tokens = {
|
| 123 |
token
|
|
@@ -185,7 +190,7 @@ def removeGlobalRename(index):
|
|
| 185 |
_write_rename(token, "")
|
| 186 |
st.session_state.pop(_global_rename_key(index), None)
|
| 187 |
del st.session_state.globalRenames[index]
|
| 188 |
-
# Shift remaining widget keys down
|
| 189 |
for i in range(index, len(st.session_state.globalRenames)):
|
| 190 |
st.session_state[_global_rename_key(i)] = list(
|
| 191 |
st.session_state.globalRenames[i]["speakers"]
|
|
@@ -263,7 +268,11 @@ def on_grename_change(idx):
|
|
| 263 |
# Write the new speakers list to the data model
|
| 264 |
kept = [t for t in prev if t in new_set]
|
| 265 |
entry["speakers"] = kept + [t for t in added]
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
# Enforce exclusivity and write renames for newly added tokens
|
| 269 |
for token in added:
|
|
@@ -272,7 +281,8 @@ def on_grename_change(idx):
|
|
| 272 |
continue
|
| 273 |
if token in other_entry["speakers"]:
|
| 274 |
other_entry["speakers"].remove(token)
|
| 275 |
-
|
|
|
|
| 276 |
_write_rename(token, "")
|
| 277 |
_write_rename(token, name)
|
| 278 |
|
|
|
|
| 113 |
"""Store tokens ('fname: SPEAKER_##') in the global categorySelect lists."""
|
| 114 |
if st.session_state.resetResult:
|
| 115 |
return
|
| 116 |
+
# Rebuild categorySelect from widget values, then sync widget keys back to
|
| 117 |
+
# match — this keeps the data model and the displayed selection in lockstep.
|
| 118 |
for i, category in enumerate(st.session_state.categories):
|
| 119 |
+
ms_key = f"multiselect_{category}"
|
| 120 |
+
new_val = list(st.session_state.get(ms_key, []))
|
| 121 |
+
st.session_state.categorySelect[i] = new_val
|
| 122 |
+
# Re-assign (don't pop) so the widget renders the correct selection on
|
| 123 |
+
# the next run. Popping causes Streamlit to fall back to [] because no
|
| 124 |
+
# `default=` is provided, wiping the visible selection.
|
| 125 |
+
st.session_state[ms_key] = new_val
|
| 126 |
# Recompute unusedSpeakers for all files
|
| 127 |
all_assigned_tokens = {
|
| 128 |
token
|
|
|
|
| 190 |
_write_rename(token, "")
|
| 191 |
st.session_state.pop(_global_rename_key(index), None)
|
| 192 |
del st.session_state.globalRenames[index]
|
| 193 |
+
# Shift remaining widget keys down and sync them to their data model
|
| 194 |
for i in range(index, len(st.session_state.globalRenames)):
|
| 195 |
st.session_state[_global_rename_key(i)] = list(
|
| 196 |
st.session_state.globalRenames[i]["speakers"]
|
|
|
|
| 268 |
# Write the new speakers list to the data model
|
| 269 |
kept = [t for t in prev if t in new_set]
|
| 270 |
entry["speakers"] = kept + [t for t in added]
|
| 271 |
+
# Sync the widget key to match the data model.
|
| 272 |
+
# Do NOT pop the key — popping causes Streamlit to re-initialise the widget
|
| 273 |
+
# to [] on the next render (because no `default=` is passed), erasing the
|
| 274 |
+
# selection visually even though the data model is correct.
|
| 275 |
+
st.session_state[grkey] = list(entry["speakers"])
|
| 276 |
|
| 277 |
# Enforce exclusivity and write renames for newly added tokens
|
| 278 |
for token in added:
|
|
|
|
| 281 |
continue
|
| 282 |
if token in other_entry["speakers"]:
|
| 283 |
other_entry["speakers"].remove(token)
|
| 284 |
+
# Sync the other entry's widget key too (same reason — don't pop)
|
| 285 |
+
st.session_state[_global_rename_key(other_idx)] = list(other_entry["speakers"])
|
| 286 |
_write_rename(token, "")
|
| 287 |
_write_rename(token, name)
|
| 288 |
|