Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Fix a bug with speaker names in left sidebar
Browse files
app.py
CHANGED
|
@@ -322,24 +322,37 @@ try:
|
|
| 322 |
stem = fname.rsplit(".", 1)[0] # strip extension
|
| 323 |
return (stem[:5] + "...") if len(stem) > 5 else stem
|
| 324 |
|
| 325 |
-
token_display_map
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
for fn in st.session_state.file_names:
|
| 327 |
if not (fn in st.session_state.results and len(st.session_state.results[fn]) == 2):
|
| 328 |
continue
|
| 329 |
short = _short_fn(fn)
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
display_speaker_tokens = list(token_display_map.keys())
|
| 344 |
|
| 345 |
# -----------------------------------------------------------------------
|
|
|
|
| 322 |
stem = fname.rsplit(".", 1)[0] # strip extension
|
| 323 |
return (stem[:5] + "...") if len(stem) > 5 else stem
|
| 324 |
|
| 325 |
+
# Build token_display_map in two passes to guarantee globally unique display keys.
|
| 326 |
+
# Pass 1: collect all (display_label -> raw_token) pairs across every file.
|
| 327 |
+
# Pass 2: any display label that appears more than once (collision between
|
| 328 |
+
# files that share the same short prefix AND speaker name) gets the
|
| 329 |
+
# raw speaker ID appended to disambiguate.
|
| 330 |
+
raw_pairs = [] # [(display_label, raw_token), ...]
|
| 331 |
for fn in st.session_state.file_names:
|
| 332 |
if not (fn in st.session_state.results and len(st.session_state.results[fn]) == 2):
|
| 333 |
continue
|
| 334 |
short = _short_fn(fn)
|
| 335 |
+
for sp in st.session_state.results[fn][0].labels():
|
| 336 |
+
raw = f"{fn}: {sp}"
|
| 337 |
+
disp = f"{short}: {get_display_name(sp, fn)}"
|
| 338 |
+
raw_pairs.append((disp, raw))
|
| 339 |
+
|
| 340 |
+
# Count occurrences of each display label globally
|
| 341 |
+
disp_counts = {}
|
| 342 |
+
for disp, _ in raw_pairs:
|
| 343 |
+
disp_counts[disp] = disp_counts.get(disp, 0) + 1
|
| 344 |
+
|
| 345 |
+
token_display_map = {}
|
| 346 |
+
for disp, raw in raw_pairs:
|
| 347 |
+
fn, sp = raw.split(": ", 1)
|
| 348 |
+
short = _short_fn(fn)
|
| 349 |
+
if disp_counts[disp] > 1:
|
| 350 |
+
# Disambiguate with raw speaker ID
|
| 351 |
+
unique_disp = f"{short}: {get_display_name(sp, fn)} ({sp})"
|
| 352 |
+
else:
|
| 353 |
+
unique_disp = disp
|
| 354 |
+
token_display_map[unique_disp] = raw
|
| 355 |
+
|
| 356 |
display_speaker_tokens = list(token_display_map.keys())
|
| 357 |
|
| 358 |
# -----------------------------------------------------------------------
|