duongthienz commited on
Commit
56539a6
·
verified ·
1 Parent(s): 2585a74

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +19 -9
ui.py CHANGED
@@ -51,9 +51,8 @@ def render_chart(fig, tab, pdf_path, svg_path, pdf_name, svg_name, pdf_key, svg_
51
  # Sidebar — categories section
52
  # ---------------------------------------------------------------------------
53
 
54
- def render_categories_sidebar(currFile, categorySelections, all_speakers_display,
55
- raw_to_display):
56
- """Render category multiselects, remove buttons, and Add custom role input."""
57
  st.sidebar.subheader("Add Speaker's Role")
58
  st.sidebar.markdown(
59
  "<p style='font-size:0.85rem; color:gray; margin-bottom:2px;'>"
@@ -62,12 +61,18 @@ def render_categories_sidebar(currFile, categorySelections, all_speakers_display
62
  unsafe_allow_html=True,
63
  )
64
  st.sidebar.divider()
 
 
 
 
 
 
 
 
65
  for i, category in enumerate(st.session_state.categories):
66
- ms_key = f"multiselect_{category}"
67
- speakerSet = categorySelections[i]
68
- default_disp = [raw_to_display.get(sp, sp) for sp in speakerSet]
69
  if ms_key not in st.session_state:
70
- st.session_state[ms_key] = default_disp
71
  label_col, trash_col = st.sidebar.columns([5, 1])
72
  label_col.markdown(f"**{category}**")
73
  trash_col.button(
@@ -75,9 +80,14 @@ def render_categories_sidebar(currFile, categorySelections, all_speakers_display
75
  on_click=removeCategory, args=(i,),
76
  help=f"Remove {category}",
77
  )
 
 
 
 
 
78
  st.sidebar.multiselect(
79
- category, all_speakers_display,
80
- key=ms_key, on_change=updateCategoryOptions, args=(currFile,),
81
  label_visibility="collapsed",
82
  )
83
  st.sidebar.text_input("Add custom role", key="categoryInput", on_change=addCategory)
 
51
  # Sidebar — categories section
52
  # ---------------------------------------------------------------------------
53
 
54
+ def render_categories_sidebar(all_speaker_tokens):
55
+ """Render cross-file role multiselects using speaker tokens, matching the rename sidebar pattern."""
 
56
  st.sidebar.subheader("Add Speaker's Role")
57
  st.sidebar.markdown(
58
  "<p style='font-size:0.85rem; color:gray; margin-bottom:2px;'>"
 
61
  unsafe_allow_html=True,
62
  )
63
  st.sidebar.divider()
64
+
65
+ # Tokens already claimed by any role, for exclusivity filtering
66
+ all_claimed = {
67
+ token
68
+ for tokens in st.session_state.categorySelect
69
+ for token in tokens
70
+ }
71
+
72
  for i, category in enumerate(st.session_state.categories):
73
+ ms_key = f"multiselect_{category}"
 
 
74
  if ms_key not in st.session_state:
75
+ st.session_state[ms_key] = list(st.session_state.categorySelect[i]) if i < len(st.session_state.categorySelect) else []
76
  label_col, trash_col = st.sidebar.columns([5, 1])
77
  label_col.markdown(f"**{category}**")
78
  trash_col.button(
 
80
  on_click=removeCategory, args=(i,),
81
  help=f"Remove {category}",
82
  )
83
+ this_role_tokens = set(st.session_state.categorySelect[i]) if i < len(st.session_state.categorySelect) else set()
84
+ available_tokens = [
85
+ t for t in all_speaker_tokens
86
+ if t not in all_claimed or t in this_role_tokens
87
+ ]
88
  st.sidebar.multiselect(
89
+ category, available_tokens,
90
+ key=ms_key, on_change=updateCategoryOptions,
91
  label_visibility="collapsed",
92
  )
93
  st.sidebar.text_input("Add custom role", key="categoryInput", on_change=addCategory)