badaoui HF Staff commited on
Commit
b9898ab
·
1 Parent(s): ddb6c31

improving code

Browse files
Files changed (1) hide show
  1. app.py +58 -92
app.py CHANGED
@@ -551,6 +551,11 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
551
 
552
 
553
 
 
 
 
 
 
554
  def get_historical_summary_plots():
555
  """Get historical summary plots from preloaded data."""
556
  plots = create_time_series_summary_gradio(Ci_results.historical_df)
@@ -559,77 +564,61 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
559
  gr.update(value=plots['amd_tests'], visible=True),
560
  gr.update(value=plots['nvidia_tests'], visible=True),
561
  )
 
 
 
 
 
 
 
 
562
 
563
  def handle_history_toggle(history_mode, last_selected_model, in_model_view):
564
- # Helper to create visibility updates efficiently
565
- hidden = gr.update(visible=False)
566
- shown = gr.update(visible=True)
567
- noop = gr.update()
568
-
569
  if history_mode:
570
- if in_model_view and last_selected_model: # Show historical model detail
 
571
  amd_ts, nvidia_ts = show_time_series_model(last_selected_model)
572
- return (hidden, shown, hidden, hidden, hidden, hidden, hidden, hidden,
573
- amd_ts, nvidia_ts, shown, noop, noop, noop, True)
574
- # Show historical summary
575
  fr_plot, amd_plot, nvidia_plot = get_historical_summary_plots()
576
- return (hidden, shown, hidden, hidden, hidden, fr_plot, amd_plot, nvidia_plot,
577
- noop, noop, hidden, noop, noop, noop, False)
578
  else:
579
- # Switch to current mode
580
  if last_selected_model and Ci_results.df is not None and not Ci_results.df.empty and last_selected_model in Ci_results.df.index:
581
  fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, last_selected_model, Ci_results.all_historical_data)
582
- return (shown, hidden, hidden, hidden, shown, hidden, hidden, hidden,
583
- noop, noop, hidden, fig, amd_txt, nvidia_txt, True)
584
- else:
585
- fig = create_summary_page(Ci_results.df, Ci_results.available_models)
586
- return (shown, hidden, shown, gr.update(value=fig, visible=True), hidden,
587
- hidden, hidden, hidden, noop, noop, hidden, noop, noop, noop, False)
588
 
 
 
 
 
 
 
 
 
 
 
 
 
589
  history_view_button.change(
590
  fn=handle_history_toggle,
591
  inputs=[history_view_button, selected_model_state, in_model_view_state],
592
  outputs=[
593
- current_view,
594
- historical_view,
595
- summary_view,
596
- summary_display,
597
- detail_view,
598
- time_series_failure_rates,
599
- time_series_amd_tests,
600
- time_series_nvidia_tests,
601
- time_series_amd_model_plot,
602
- time_series_nvidia_model_plot,
603
- time_series_detail_view,
604
- plot_output,
605
- amd_failed_tests_output,
606
- nvidia_failed_tests_output,
607
- in_model_view_state,
608
  ],
609
  )
610
 
611
-
612
- # Time-series model selection functionality
613
- def show_time_series_model(selected_model):
614
- """Show time-series view for a specific model."""
615
- plots = create_model_time_series_gradio(Ci_results.historical_df, selected_model)
616
- return (
617
- gr.update(value=plots['amd_plot'], visible=True),
618
- gr.update(value=plots['nvidia_plot'], visible=True),
619
- )
620
-
621
- # Unified model click handler: respects History toggle
622
- def handle_model_click(selected_model: str, history_mode: bool):
623
- noop, hidden, shown = gr.update(), gr.update(visible=False), gr.update(visible=True)
624
- if history_mode:
625
- amd_ts, nvidia_ts = show_time_series_model(selected_model)
626
- return (noop, noop, noop, hidden, shown, hidden, hidden, hidden, hidden, hidden,
627
- hidden, amd_ts, nvidia_ts, shown, selected_model, True)
628
- else:
629
- fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, selected_model, Ci_results.all_historical_data)
630
- return (fig, amd_txt, nvidia_txt, shown, hidden, hidden, hidden, shown, noop, noop,
631
- noop, noop, noop, hidden, selected_model, True)
632
-
633
  # Define common outputs for model click handlers
634
  model_click_outputs = [
635
  plot_output, amd_failed_tests_output, nvidia_failed_tests_output,
@@ -639,44 +628,21 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
639
  selected_model_state, in_model_view_state,
640
  ]
641
 
642
- # Wire up all model buttons
643
- for i, btn in enumerate(model_buttons):
644
- model_name = model_choices[i]
645
- btn.click(
646
- fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
647
- inputs=[history_view_button],
648
- outputs=model_click_outputs,
649
- )
650
-
651
- # Wire up AMD failing model buttons
652
- amd_models_to_show = amd_failing_models + both_failing_models
653
- for i, btn in enumerate(amd_buttons):
654
- model_name = sorted(amd_models_to_show)[i]
655
- btn.click(
656
- fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
657
- inputs=[history_view_button],
658
- outputs=model_click_outputs,
659
- )
660
-
661
- # Wire up NVIDIA failing model buttons
662
- nvidia_models_to_show = nvidia_failing_models + both_failing_models
663
- for i, btn in enumerate(nvidia_buttons):
664
- model_name = sorted(nvidia_models_to_show)[i]
665
- btn.click(
666
- fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
667
- inputs=[history_view_button],
668
- outputs=model_click_outputs,
669
- )
670
 
671
- # Wire up both failures model buttons
672
- all_failing = list(set(amd_failing_models + nvidia_failing_models + both_failing_models))
673
- for i, btn in enumerate(both_buttons):
674
- model_name = sorted(all_failing)[i]
675
- btn.click(
676
- fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
677
- inputs=[history_view_button],
678
- outputs=model_click_outputs,
679
- )
680
 
681
  # Summary button click handler
682
  def show_summary_and_update_links():
 
551
 
552
 
553
 
554
+ # Constants for Gradio updates
555
+ HIDDEN = gr.update(visible=False)
556
+ SHOWN = gr.update(visible=True)
557
+ NOOP = gr.update()
558
+
559
  def get_historical_summary_plots():
560
  """Get historical summary plots from preloaded data."""
561
  plots = create_time_series_summary_gradio(Ci_results.historical_df)
 
564
  gr.update(value=plots['amd_tests'], visible=True),
565
  gr.update(value=plots['nvidia_tests'], visible=True),
566
  )
567
+
568
+ def show_time_series_model(selected_model):
569
+ """Show time-series view for a specific model."""
570
+ plots = create_model_time_series_gradio(Ci_results.historical_df, selected_model)
571
+ return (
572
+ gr.update(value=plots['amd_plot'], visible=True),
573
+ gr.update(value=plots['nvidia_plot'], visible=True),
574
+ )
575
 
576
  def handle_history_toggle(history_mode, last_selected_model, in_model_view):
577
+ """Handle toggling between current and historical view."""
 
 
 
 
578
  if history_mode:
579
+ # Historical mode: show model detail if in model view, otherwise summary
580
+ if in_model_view and last_selected_model:
581
  amd_ts, nvidia_ts = show_time_series_model(last_selected_model)
582
+ return (HIDDEN, SHOWN, HIDDEN, HIDDEN, HIDDEN, HIDDEN, HIDDEN, HIDDEN,
583
+ amd_ts, nvidia_ts, SHOWN, NOOP, NOOP, NOOP, True)
584
+
585
  fr_plot, amd_plot, nvidia_plot = get_historical_summary_plots()
586
+ return (HIDDEN, SHOWN, HIDDEN, HIDDEN, HIDDEN, fr_plot, amd_plot, nvidia_plot,
587
+ NOOP, NOOP, HIDDEN, NOOP, NOOP, NOOP, False)
588
  else:
589
+ # Current mode: show model detail if available, otherwise summary
590
  if last_selected_model and Ci_results.df is not None and not Ci_results.df.empty and last_selected_model in Ci_results.df.index:
591
  fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, last_selected_model, Ci_results.all_historical_data)
592
+ return (SHOWN, HIDDEN, HIDDEN, HIDDEN, SHOWN, HIDDEN, HIDDEN, HIDDEN,
593
+ NOOP, NOOP, HIDDEN, fig, amd_txt, nvidia_txt, True)
594
+
595
+ fig = create_summary_page(Ci_results.df, Ci_results.available_models)
596
+ return (SHOWN, HIDDEN, SHOWN, gr.update(value=fig, visible=True), HIDDEN,
597
+ HIDDEN, HIDDEN, HIDDEN, NOOP, NOOP, HIDDEN, NOOP, NOOP, NOOP, False)
598
 
599
+ def handle_model_click(selected_model: str, history_mode: bool):
600
+ """Handle clicking on a model button."""
601
+ if history_mode:
602
+ amd_ts, nvidia_ts = show_time_series_model(selected_model)
603
+ return (NOOP, NOOP, NOOP, HIDDEN, SHOWN, HIDDEN, HIDDEN, HIDDEN, HIDDEN, HIDDEN,
604
+ HIDDEN, amd_ts, nvidia_ts, SHOWN, selected_model, True)
605
+
606
+ fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, selected_model, Ci_results.all_historical_data)
607
+ return (fig, amd_txt, nvidia_txt, SHOWN, HIDDEN, HIDDEN, HIDDEN, SHOWN, NOOP, NOOP,
608
+ NOOP, NOOP, NOOP, HIDDEN, selected_model, True)
609
+
610
+ # Wire up history toggle
611
  history_view_button.change(
612
  fn=handle_history_toggle,
613
  inputs=[history_view_button, selected_model_state, in_model_view_state],
614
  outputs=[
615
+ current_view, historical_view, summary_view, summary_display, detail_view,
616
+ time_series_failure_rates, time_series_amd_tests, time_series_nvidia_tests,
617
+ time_series_amd_model_plot, time_series_nvidia_model_plot, time_series_detail_view,
618
+ plot_output, amd_failed_tests_output, nvidia_failed_tests_output, in_model_view_state,
 
 
 
 
 
 
 
 
 
 
 
619
  ],
620
  )
621
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
  # Define common outputs for model click handlers
623
  model_click_outputs = [
624
  plot_output, amd_failed_tests_output, nvidia_failed_tests_output,
 
628
  selected_model_state, in_model_view_state,
629
  ]
630
 
631
+ # Helper function to connect button clicks
632
+ def connect_model_buttons(buttons, models):
633
+ """Connect a list of buttons to their corresponding models."""
634
+ for btn, model_name in zip(buttons, models):
635
+ btn.click(
636
+ fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
637
+ inputs=[history_view_button],
638
+ outputs=model_click_outputs,
639
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
640
 
641
+ # Wire up all button groups
642
+ connect_model_buttons(model_buttons, model_choices)
643
+ connect_model_buttons(amd_buttons, sorted(amd_failing_models + both_failing_models))
644
+ connect_model_buttons(nvidia_buttons, sorted(nvidia_failing_models + both_failing_models))
645
+ connect_model_buttons(both_buttons, sorted(list(set(amd_failing_models + nvidia_failing_models + both_failing_models))))
 
 
 
 
646
 
647
  # Summary button click handler
648
  def show_summary_and_update_links():