duongthienz commited on
Commit
6b64fdd
Β·
verified Β·
1 Parent(s): ab1a728

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +66 -65
ui.py CHANGED
@@ -416,54 +416,27 @@ def render_multifile_summary(plotly_config=None):
416
  for i, col in enumerate(allCategories)
417
  }
418
 
419
- with st.container():
420
- fig6_sort_options = {
421
- "File Name": ("files", True),
422
- "% of Instructor": ("Instructor", False),
423
- }
424
- selected_fig6_sort = st.selectbox(
425
- "Sort by:",
426
- options=list(fig6_sort_options.keys()),
427
- key="multifile_role_sort",
428
- )
429
- fig6_sort_col, fig6_ascending = fig6_sort_options[selected_fig6_sort]
430
- # Gracefully fall back to file name if Instructor column missing
431
- if fig6_sort_col not in df6.columns:
432
- fig6_sort_col, fig6_ascending = "files", True
433
- fig6 = px.bar(df6.sort_values(fig6_sort_col, ascending=fig6_ascending),
434
- x="files", y=allCategories,
435
- title="Percent of File Duration Spoken by Each Speaker/Role",
436
- labels={"files": "Files"},
437
- color_discrete_map=role_color_map,
438
- hover_data={"files": True})
439
- fig6.update_layout(yaxis_title="% of File Duration")
440
- fig6.update_xaxes(showticklabels=False)
441
- st.plotly_chart(fig6, use_container_width=True, config=cfg)
442
-
443
- with st.container():
444
- sort_options = {
445
- "File Name": ("files", True),
446
- "% of Single Voice": ("Single Voice", False),
447
- }
448
- selected_sort = st.selectbox(
449
- "Sort cross-file voice categories by:",
450
- options=list(sort_options.keys()),
451
- key="multifile_voice_sort",
452
- )
453
- sort_col, ascending = sort_options[selected_sort]
454
- fig7 = px.bar(
455
- df7.sort_values(by=sort_col, ascending=ascending),
456
- x="files", y=["Single Voice", "Multi Voice", "No Voice"],
457
- title=f"Cross-file Voice Categories sorted by {selected_sort}",
458
- labels={"files": "Files"},
459
- color_discrete_map=voice_color_map,
460
- hover_data={"files": True},
461
- )
462
- fig7.update_layout(yaxis_title="% of File Duration")
463
- fig7.update_xaxes(showticklabels=False)
464
- st.plotly_chart(fig7, use_container_width=True, config=cfg)
465
 
466
- st.divider()
 
 
 
 
 
 
 
 
467
 
468
  # New chart: Single Voice broken down by role, plus Multi Voice and No Voice
469
  df8, role_voice_cols = utils.build_multifile_role_voice_df(
@@ -479,25 +452,53 @@ def render_multifile_summary(plotly_config=None):
479
  }
480
  role_voice_color_map.update(voice_color_map)
481
 
482
- with st.container():
483
- role_sort_options = {
484
- "File Name": ("files", True),
485
- "% of Multi Voice": ("Multi Voice", False),
486
- }
 
 
 
 
487
 
488
- selected_role_sort = st.selectbox(
489
- "Sort cross-file role/voice breakdown by:",
490
- options=list(role_sort_options.keys()),
491
- key="multifile_role_voice_sort",
492
- )
493
- sort_col8, ascending8 = role_sort_options[selected_role_sort]
494
- fig8 = px.bar(
495
- df8.sort_values(by=sort_col8, ascending=ascending8),
496
- x="files", y=role_voice_cols,
497
- color_discrete_map=role_voice_color_map,
498
- labels={"files": "Files"},
499
- hover_data={"files": True},
500
- title=f"Cross-file Role & Voice Breakdown sorted by {selected_role_sort}",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  )
502
  fig8.update_layout(yaxis_title="% of File Duration")
503
  fig8.update_xaxes(showticklabels=False)
 
416
  for i, col in enumerate(allCategories)
417
  }
418
 
419
+ # All three sort selectors rendered FIRST (above their charts) so
420
+ # selectbox reruns don't cause the page to scroll downward.
421
+ fig6_sort_options = {
422
+ "File Name": ("files", True),
423
+ "% of Instructor": ("Instructor", False),
424
+ }
425
+ selected_fig6_sort = st.selectbox(
426
+ "Sort Percent of File Duration by:",
427
+ options=list(fig6_sort_options.keys()),
428
+ key="multifile_role_sort",
429
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
 
431
+ sort_options = {
432
+ "File Name": ("files", True),
433
+ "% of Single Voice": ("Single Voice", False),
434
+ }
435
+ selected_sort = st.selectbox(
436
+ "Sort Cross-file Voice Categories by:",
437
+ options=list(sort_options.keys()),
438
+ key="multifile_voice_sort",
439
+ )
440
 
441
  # New chart: Single Voice broken down by role, plus Multi Voice and No Voice
442
  df8, role_voice_cols = utils.build_multifile_role_voice_df(
 
452
  }
453
  role_voice_color_map.update(voice_color_map)
454
 
455
+ role_sort_options = {
456
+ "File Name": ("files", True),
457
+ "% of Multi Voice": ("Multi Voice", True), # least β†’ most
458
+ }
459
+ selected_role_sort = st.selectbox(
460
+ "Sort Cross-file Role & Voice Breakdown by:",
461
+ options=list(role_sort_options.keys()),
462
+ key="multifile_role_voice_sort",
463
+ )
464
 
465
+ # ── Charts rendered below all selectors ──────────────────────────
466
+ fig6_sort_col, fig6_ascending = fig6_sort_options[selected_fig6_sort]
467
+ if fig6_sort_col not in df6.columns:
468
+ fig6_sort_col, fig6_ascending = "files", True
469
+ fig6 = px.bar(df6.sort_values(fig6_sort_col, ascending=fig6_ascending),
470
+ x="files", y=allCategories,
471
+ title="Percent of File Duration Spoken by Each Speaker/Role",
472
+ labels={"files": "Files"},
473
+ color_discrete_map=role_color_map,
474
+ hover_data={"files": True})
475
+ fig6.update_layout(yaxis_title="% of File Duration")
476
+ fig6.update_xaxes(showticklabels=False)
477
+ st.plotly_chart(fig6, use_container_width=True, config=cfg)
478
+
479
+ sort_col, ascending = sort_options[selected_sort]
480
+ fig7 = px.bar(
481
+ df7.sort_values(by=sort_col, ascending=ascending),
482
+ x="files", y=["Single Voice", "Multi Voice", "No Voice"],
483
+ title=f"Cross-file Voice Categories sorted by {selected_sort}",
484
+ labels={"files": "Files"},
485
+ color_discrete_map=voice_color_map,
486
+ hover_data={"files": True},
487
+ )
488
+ fig7.update_layout(yaxis_title="% of File Duration")
489
+ fig7.update_xaxes(showticklabels=False)
490
+ st.plotly_chart(fig7, use_container_width=True, config=cfg)
491
+
492
+ st.divider()
493
+
494
+ sort_col8, ascending8 = role_sort_options[selected_role_sort]
495
+ fig8 = px.bar(
496
+ df8.sort_values(by=sort_col8, ascending=ascending8),
497
+ x="files", y=role_voice_cols,
498
+ color_discrete_map=role_voice_color_map,
499
+ labels={"files": "Files"},
500
+ hover_data={"files": True},
501
+ title=f"Cross-file Role & Voice Breakdown sorted by {selected_role_sort}",
502
  )
503
  fig8.update_layout(yaxis_title="% of File Duration")
504
  fig8.update_xaxes(showticklabels=False)