duongthienz commited on
Commit
2824942
·
verified ·
1 Parent(s): 5cff7cf

revert left sidebar naming scheme and add a hover mouse feature

Browse files

the naming scheme was causing a lot of trouble with dict handling

Files changed (1) hide show
  1. app.py +18 -38
app.py CHANGED
@@ -111,6 +111,10 @@ st.markdown(
111
  "details > summary { font-size: 1rem; font-weight: 500; }"
112
  ".stTabs [data-baseweb='tab'] { font-size: 1rem; }"
113
  ".stFileUploader label { font-size: 1rem; }"
 
 
 
 
114
  "</style>",
115
  unsafe_allow_html=True,
116
  )
@@ -312,47 +316,23 @@ try:
312
  for sp in st.session_state.results[fn][0].labels()
313
  ]
314
  # Map display label -> raw token so ui.py can translate back after selection.
315
- # Display label uses a truncated filename (first 5 chars + "...") to keep
316
- # the dropdown readable when filenames are long. The raw token always uses
317
- # the full filename so the data model is never affected by this truncation.
318
- # If two speakers in the same file share a display name, the raw speaker ID
319
- # is appended to disambiguate both entries.
320
- def _short_fn(fname):
321
- """Return first 5 chars of filename stem + '...' if longer than 5."""
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
  # -----------------------------------------------------------------------
 
111
  "details > summary { font-size: 1rem; font-weight: 500; }"
112
  ".stTabs [data-baseweb='tab'] { font-size: 1rem; }"
113
  ".stFileUploader label { font-size: 1rem; }"
114
+ /* Multiselect: show full label on hover when text is truncated */
115
+ "[data-baseweb='tag'] span { cursor: default; }"
116
+ "[data-baseweb='menu'] li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }"
117
+ "[data-baseweb='menu'] li:hover { overflow: visible; white-space: normal; z-index: 9999; }"
118
  "</style>",
119
  unsafe_allow_html=True,
120
  )
 
316
  for sp in st.session_state.results[fn][0].labels()
317
  ]
318
  # Map display label -> raw token so ui.py can translate back after selection.
319
+ # If two speakers in the same file share a display name, append the raw ID
320
+ # to disambiguate both entries.
321
+ token_display_map = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  for fn in st.session_state.file_names:
323
  if not (fn in st.session_state.results and len(st.session_state.results[fn]) == 2):
324
  continue
325
+ sp_labels = {sp: f"{fn}: {get_display_name(sp, fn)}"
326
+ for sp in st.session_state.results[fn][0].labels()}
327
+ label_counts = {}
328
+ for disp in sp_labels.values():
329
+ label_counts[disp] = label_counts.get(disp, 0) + 1
330
+ for sp, disp in sp_labels.items():
331
+ raw = f"{fn}: {sp}"
332
+ if label_counts[disp] > 1:
333
+ token_display_map[f"{fn}: {get_display_name(sp, fn)} ({sp})"] = raw
334
+ else:
335
+ token_display_map[disp] = raw
 
 
 
 
 
 
 
 
 
 
 
336
  display_speaker_tokens = list(token_display_map.keys())
337
 
338
  # -----------------------------------------------------------------------