duongthienz commited on
Commit
60aa939
·
verified ·
1 Parent(s): fb4bcdd

Update state.py

Browse files
Files changed (1) hide show
  1. state.py +8 -7
state.py CHANGED
@@ -144,6 +144,7 @@ def _global_rename_key(index):
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
@@ -151,6 +152,8 @@ def applyGlobalRenames():
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:
@@ -184,6 +187,7 @@ def applyGlobalRenames():
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]
@@ -194,21 +198,18 @@ def applyGlobalRenames():
194
 
195
 
196
  def enforceGlobalRenameExclusivity(changed_idx):
197
- """Ensure a token assigned to entry[changed_idx] is removed from all others.
198
-
199
- Called by the sidebar multiselect on_change so that picking a speaker for
200
- one name automatically unassigns it from any previously-holding name.
201
- We pop (not overwrite) stale widget keys to avoid the Streamlit
202
- "cannot modify after instantiation" error.
203
- """
204
  changed_tokens = set(st.session_state.globalRenames[changed_idx]["speakers"])
 
205
  for idx, entry in enumerate(st.session_state.globalRenames):
206
  if idx == changed_idx:
207
  continue
208
  new_speakers = [t for t in entry["speakers"] if t not in changed_tokens]
 
209
  if new_speakers != entry["speakers"]:
210
  entry["speakers"] = new_speakers
211
  st.session_state.pop(_global_rename_key(idx), None)
 
212
  applyGlobalRenames()
213
 
214
 
 
144
 
145
  def applyGlobalRenames():
146
  """Sync speakerRenames from globalRenames without clobbering inline-only renames.
147
+ DEBUG VERSION.
148
 
149
  Strategy: only touch speakers whose token appears in globalRenames. Speakers
150
  with no globalRenames entry keep whatever speakerRenames already has for them
 
152
  that was made via the Rename Speaker tab but whose token was later removed from
153
  a globalRenames entry.
154
  """
155
+ print(f"[DEBUG applyGlobalRenames] globalRenames={st.session_state.globalRenames}")
156
+ print(f"[DEBUG applyGlobalRenames] speakerRenames before={st.session_state.speakerRenames}")
157
  # Build a map of token -> display_name from globalRenames
158
  token_to_name: dict = {}
159
  for entry in st.session_state.globalRenames:
 
187
  if fname in st.session_state.speakerRenames:
188
  st.session_state.speakerRenames[fname][raw_sp] = name
189
 
190
+ print(f"[DEBUG applyGlobalRenames] speakerRenames after={st.session_state.speakerRenames}")
191
  curr = st.session_state.get("select_currFile")
192
  if curr and curr in st.session_state.speakerRenames:
193
  saved = st.session_state.speakerRenames[curr]
 
198
 
199
 
200
  def enforceGlobalRenameExclusivity(changed_idx):
201
+ """Ensure a token assigned to entry[changed_idx] is removed from all others."""
 
 
 
 
 
 
202
  changed_tokens = set(st.session_state.globalRenames[changed_idx]["speakers"])
203
+ print(f"[DEBUG enforceExclusivity] idx={changed_idx} tokens={changed_tokens}")
204
  for idx, entry in enumerate(st.session_state.globalRenames):
205
  if idx == changed_idx:
206
  continue
207
  new_speakers = [t for t in entry["speakers"] if t not in changed_tokens]
208
+ print(f"[DEBUG enforceExclusivity] entry[{idx}] {entry['name']}: {entry['speakers']} -> {new_speakers}")
209
  if new_speakers != entry["speakers"]:
210
  entry["speakers"] = new_speakers
211
  st.session_state.pop(_global_rename_key(idx), None)
212
+ print(f"[DEBUG enforceExclusivity] globalRenames after: {st.session_state.globalRenames}")
213
  applyGlobalRenames()
214
 
215