duongthienz commited on
Commit
1fb0de9
·
verified ·
1 Parent(s): a1d5d0b

Fix a bug with conflicted speakers in the same rename

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -271,13 +271,26 @@ try:
271
  if fn in st.session_state.results and len(st.session_state.results[fn]) == 2
272
  for sp in st.session_state.results[fn][0].labels()
273
  ]
274
- # Map display label -> raw token so ui.py can translate back after selection
275
- token_display_map = {
276
- f"{fn}: {get_display_name(sp, fn)}": f"{fn}: {sp}"
277
- for fn in st.session_state.file_names
278
- if fn in st.session_state.results and len(st.session_state.results[fn]) == 2
279
- for sp in st.session_state.results[fn][0].labels()
280
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  display_speaker_tokens = list(token_display_map.keys())
282
 
283
  # -----------------------------------------------------------------------
 
271
  if fn in st.session_state.results and len(st.session_state.results[fn]) == 2
272
  for sp in st.session_state.results[fn][0].labels()
273
  ]
274
+ # Map display label -> raw token so ui.py can translate back after selection.
275
+ # Build carefully to avoid key collisions: if two speakers in the same file
276
+ # share a display name, append the raw ID to disambiguate both entries.
277
+ token_display_map = {}
278
+ for fn in st.session_state.file_names:
279
+ if not (fn in st.session_state.results and len(st.session_state.results[fn]) == 2):
280
+ continue
281
+ # First pass: collect display labels per file to detect duplicates
282
+ sp_labels = {sp: f"{fn}: {get_display_name(sp, fn)}"
283
+ for sp in st.session_state.results[fn][0].labels()}
284
+ label_counts = {}
285
+ for disp in sp_labels.values():
286
+ label_counts[disp] = label_counts.get(disp, 0) + 1
287
+ # Second pass: build map, disambiguating where needed
288
+ for sp, disp in sp_labels.items():
289
+ raw = f"{fn}: {sp}"
290
+ if label_counts[disp] > 1:
291
+ token_display_map[f"{fn}: {get_display_name(sp, fn)} ({sp})"] = raw
292
+ else:
293
+ token_display_map[disp] = raw
294
  display_speaker_tokens = list(token_display_map.keys())
295
 
296
  # -----------------------------------------------------------------------