Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
fix a bug between rename multiple speaker and rename speaker
Browse files
state.py
CHANGED
|
@@ -143,17 +143,47 @@ def _global_rename_key(index):
|
|
| 143 |
|
| 144 |
|
| 145 |
def applyGlobalRenames():
|
| 146 |
-
"""
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
for entry in st.session_state.globalRenames:
|
| 150 |
-
display_name = entry["name"]
|
| 151 |
for token in entry["speakers"]:
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
curr = st.session_state.get("select_currFile")
|
| 158 |
if curr and curr in st.session_state.speakerRenames:
|
| 159 |
saved = st.session_state.speakerRenames[curr]
|
|
|
|
| 143 |
|
| 144 |
|
| 145 |
def applyGlobalRenames():
|
| 146 |
+
"""Sync speakerRenames from globalRenames without clobbering inline-only renames.
|
| 147 |
+
|
| 148 |
+
Strategy: only touch speakers whose token appears in globalRenames. Speakers
|
| 149 |
+
with no globalRenames entry keep whatever speakerRenames already has for them
|
| 150 |
+
(set by apply_inline_rename). This prevents the sidebar from wiping a rename
|
| 151 |
+
that was made via the Rename Speaker tab but whose token was later removed from
|
| 152 |
+
a globalRenames entry.
|
| 153 |
+
"""
|
| 154 |
+
# Build a map of token -> display_name from globalRenames
|
| 155 |
+
token_to_name: dict = {}
|
| 156 |
for entry in st.session_state.globalRenames:
|
|
|
|
| 157 |
for token in entry["speakers"]:
|
| 158 |
+
token_to_name[token] = entry["name"]
|
| 159 |
+
|
| 160 |
+
# Collect every token that exists in ANY globalRenames entry (assigned or not)
|
| 161 |
+
all_global_tokens: set = {
|
| 162 |
+
token
|
| 163 |
+
for entry in st.session_state.globalRenames
|
| 164 |
+
for token in entry["speakers"]
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
for fname in st.session_state.speakerRenames:
|
| 168 |
+
renames = st.session_state.speakerRenames[fname]
|
| 169 |
+
for sp in list(renames.keys()):
|
| 170 |
+
token = f"{fname}: {sp}"
|
| 171 |
+
if token in token_to_name:
|
| 172 |
+
# Overwrite with the current globalRenames name
|
| 173 |
+
renames[sp] = token_to_name[token]
|
| 174 |
+
elif token in all_global_tokens:
|
| 175 |
+
# Token was explicitly unassigned from all entries — clear the rename
|
| 176 |
+
del renames[sp]
|
| 177 |
+
# else: inline-only rename with no globalRenames record — leave untouched
|
| 178 |
+
|
| 179 |
+
# Apply any newly assigned tokens not yet in speakerRenames
|
| 180 |
+
for token, name in token_to_name.items():
|
| 181 |
+
if ": " not in token:
|
| 182 |
+
continue
|
| 183 |
+
fname, raw_sp = token.split(": ", 1)
|
| 184 |
+
if fname in st.session_state.speakerRenames:
|
| 185 |
+
st.session_state.speakerRenames[fname][raw_sp] = name
|
| 186 |
+
|
| 187 |
curr = st.session_state.get("select_currFile")
|
| 188 |
if curr and curr in st.session_state.speakerRenames:
|
| 189 |
saved = st.session_state.speakerRenames[curr]
|