badaoui HF Staff commited on
Commit
941f5e0
·
1 Parent(s): 6fc74fe

some code optimization

Browse files
Files changed (5) hide show
  1. app.py +43 -208
  2. model_page.py +2 -8
  3. summary_page.py +2 -8
  4. time_series_gradio.py +1 -9
  5. utils.py +12 -0
app.py CHANGED
@@ -507,40 +507,17 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
507
  def handle_summary_click(history_mode: bool):
508
  description = get_description_text()
509
  links = get_ci_links()
510
- fr_plot, amd_plot, nvidia_plot = get_historical_summary_plots()
511
  if history_mode:
512
- return (
513
- description,
514
- links,
515
- gr.update(visible=False), # current_view
516
- gr.update(visible=True), # historical_view
517
- gr.update(visible=False), # summary_view
518
- gr.update(visible=False), # summary_display
519
- gr.update(visible=False), # detail_view
520
- fr_plot,
521
- amd_plot,
522
- nvidia_plot,
523
- gr.update(visible=False), # time_series_detail_view
524
- False, # in_model_view_state
525
- "", # selected_model_state (clear it)
526
- )
527
  else:
528
  fig = create_summary_page(Ci_results.df, Ci_results.available_models)
529
- return (
530
- description,
531
- links,
532
- gr.update(visible=True), # current_view
533
- gr.update(visible=False), # historical_view
534
- gr.update(visible=True), # summary_view
535
- gr.update(value=fig, visible=True), # summary_display
536
- gr.update(visible=False), # detail_view
537
- gr.update(visible=False), # time_series_failure_rates
538
- gr.update(visible=False), # time_series_amd_tests
539
- gr.update(visible=False), # time_series_nvidia_tests
540
- gr.update(visible=False), # time_series_detail_view
541
- False, # in_model_view_state
542
- "", # selected_model_state (clear it)
543
- )
544
 
545
  summary_button.click(
546
  fn=handle_summary_click,
@@ -643,86 +620,30 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
643
  )
644
 
645
  def handle_history_toggle(history_mode, last_selected_model, in_model_view):
 
 
 
 
 
646
  if history_mode:
647
- # If currently in model view and valid model, show historical model detail
648
- if in_model_view and last_selected_model:
649
  amd_ts, nvidia_ts = show_time_series_model(last_selected_model)
650
- return (
651
- gr.update(visible=False), # current_view
652
- gr.update(visible=True), # historical_view
653
- gr.update(visible=False), # summary_view
654
- gr.update(visible=False), # summary_display
655
- gr.update(visible=False), # detail_view
656
- gr.update(visible=False), # time_series_failure_rates
657
- gr.update(visible=False), # time_series_amd_tests
658
- gr.update(visible=False), # time_series_nvidia_tests
659
- amd_ts, # time_series_amd_model_plot
660
- nvidia_ts, # time_series_nvidia_model_plot
661
- gr.update(visible=True), # time_series_detail_view
662
- gr.update(), # plot_output
663
- gr.update(), # amd_failed_tests_output
664
- gr.update(), # nvidia_failed_tests_output
665
- True, # in_model_view_state (still in model view)
666
- )
667
- # Otherwise show historical summary
668
  fr_plot, amd_plot, nvidia_plot = get_historical_summary_plots()
669
- return (
670
- gr.update(visible=False), # current_view
671
- gr.update(visible=True), # historical_view
672
- gr.update(visible=False), # summary_view
673
- gr.update(visible=False), # summary_display
674
- gr.update(visible=False), # detail_view
675
- fr_plot, # time_series_failure_rates (value + keep visibility)
676
- amd_plot, # time_series_amd_tests
677
- nvidia_plot, # time_series_nvidia_tests
678
- gr.update(), # time_series_amd_model_plot
679
- gr.update(), # time_series_nvidia_model_plot
680
- gr.update(visible=False), # time_series_detail_view
681
- gr.update(), # plot_output
682
- gr.update(), # amd_failed_tests_output
683
- gr.update(), # nvidia_failed_tests_output
684
- False, # in_model_view_state
685
- )
686
  else:
687
- # Switch to current mode: show model if selected; otherwise summary
688
  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:
689
  fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, last_selected_model, Ci_results.all_historical_data)
690
- return (
691
- gr.update(visible=True), # current_view
692
- gr.update(visible=False), # historical_view
693
- gr.update(visible=False), # summary_view
694
- gr.update(visible=False), # summary_display
695
- gr.update(visible=True), # detail_view
696
- gr.update(visible=False), # time_series_failure_rates
697
- gr.update(visible=False), # time_series_amd_tests
698
- gr.update(visible=False), # time_series_nvidia_tests
699
- gr.update(), # time_series_amd_model_plot
700
- gr.update(), # time_series_nvidia_model_plot
701
- gr.update(visible=False), # time_series_detail_view
702
- fig, # plot_output
703
- amd_txt, # amd_failed_tests_output
704
- nvidia_txt, # nvidia_failed_tests_output
705
- True, # in_model_view_state
706
- )
707
  else:
708
  fig = create_summary_page(Ci_results.df, Ci_results.available_models)
709
- return (
710
- gr.update(visible=True), # current_view
711
- gr.update(visible=False), # historical_view
712
- gr.update(visible=True), # summary_view
713
- gr.update(value=fig, visible=True), # summary_display
714
- gr.update(visible=False), # detail_view
715
- gr.update(visible=False), # time_series_failure_rates
716
- gr.update(visible=False), # time_series_amd_tests
717
- gr.update(visible=False), # time_series_nvidia_tests
718
- gr.update(), # time_series_amd_model_plot
719
- gr.update(), # time_series_nvidia_model_plot
720
- gr.update(visible=False), # time_series_detail_view
721
- gr.update(), # plot_output
722
- gr.update(), # amd_failed_tests_output
723
- gr.update(), # nvidia_failed_tests_output
724
- False, # in_model_view_state
725
- )
726
 
727
  history_view_button.change(
728
  fn=handle_history_toggle,
@@ -758,67 +679,32 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
758
 
759
  # Unified model click handler: respects History toggle
760
  def handle_model_click(selected_model: str, history_mode: bool):
 
761
  if history_mode:
762
  amd_ts, nvidia_ts = show_time_series_model(selected_model)
763
- return (
764
- gr.update(), # plot_output
765
- gr.update(), # amd_failed_tests_output
766
- gr.update(), # nvidia_failed_tests_output
767
- gr.update(visible=False), # current_view
768
- gr.update(visible=True), # historical_view
769
- gr.update(visible=False), # summary_view
770
- gr.update(visible=False), # summary_display
771
- gr.update(visible=False), # detail_view
772
- gr.update(visible=False), # time_series_failure_rates
773
- gr.update(visible=False), # time_series_amd_tests
774
- gr.update(visible=False), # time_series_nvidia_tests
775
- amd_ts, # time_series_amd_model_plot
776
- nvidia_ts, # time_series_nvidia_model_plot
777
- gr.update(visible=True), # time_series_detail_view
778
- selected_model, True) # selected_model_state, in_model_view_state
779
  else:
780
  fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, selected_model, Ci_results.all_historical_data)
781
- return (
782
- fig,
783
- amd_txt,
784
- nvidia_txt,
785
- gr.update(visible=True), # current_view
786
- gr.update(visible=False), # historical_view
787
- gr.update(visible=False), # summary_view
788
- gr.update(visible=False), # summary_display
789
- gr.update(visible=True), # detail_view
790
- gr.update(), # time_series_failure_rates
791
- gr.update(), # time_series_amd_tests
792
- gr.update(), # time_series_nvidia_tests
793
- gr.update(), # time_series_amd_model_plot
794
- gr.update(), # time_series_nvidia_model_plot
795
- gr.update(visible=False), # time_series_detail_view
796
- selected_model, True) # selected_model_state, in_model_view_state
797
-
798
  # Wire up all model buttons
799
  for i, btn in enumerate(model_buttons):
800
  model_name = model_choices[i]
801
  btn.click(
802
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
803
  inputs=[history_view_button],
804
- outputs=[
805
- plot_output,
806
- amd_failed_tests_output,
807
- nvidia_failed_tests_output,
808
- current_view,
809
- historical_view,
810
- summary_view,
811
- summary_display,
812
- detail_view,
813
- time_series_failure_rates,
814
- time_series_amd_tests,
815
- time_series_nvidia_tests,
816
- time_series_amd_model_plot,
817
- time_series_nvidia_model_plot,
818
- time_series_detail_view,
819
- selected_model_state,
820
- in_model_view_state,
821
- ],
822
  )
823
 
824
  # Wire up AMD failing model buttons
@@ -828,24 +714,7 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
828
  btn.click(
829
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
830
  inputs=[history_view_button],
831
- outputs=[
832
- plot_output,
833
- amd_failed_tests_output,
834
- nvidia_failed_tests_output,
835
- current_view,
836
- historical_view,
837
- summary_view,
838
- summary_display,
839
- detail_view,
840
- time_series_failure_rates,
841
- time_series_amd_tests,
842
- time_series_nvidia_tests,
843
- time_series_amd_model_plot,
844
- time_series_nvidia_model_plot,
845
- time_series_detail_view,
846
- selected_model_state,
847
- in_model_view_state,
848
- ],
849
  )
850
 
851
  # Wire up NVIDIA failing model buttons
@@ -855,24 +724,7 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
855
  btn.click(
856
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
857
  inputs=[history_view_button],
858
- outputs=[
859
- plot_output,
860
- amd_failed_tests_output,
861
- nvidia_failed_tests_output,
862
- current_view,
863
- historical_view,
864
- summary_view,
865
- summary_display,
866
- detail_view,
867
- time_series_failure_rates,
868
- time_series_amd_tests,
869
- time_series_nvidia_tests,
870
- time_series_amd_model_plot,
871
- time_series_nvidia_model_plot,
872
- time_series_detail_view,
873
- selected_model_state,
874
- in_model_view_state,
875
- ],
876
  )
877
 
878
  # Wire up both failures model buttons
@@ -882,24 +734,7 @@ with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), js=js_func)
882
  btn.click(
883
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
884
  inputs=[history_view_button],
885
- outputs=[
886
- plot_output,
887
- amd_failed_tests_output,
888
- nvidia_failed_tests_output,
889
- current_view,
890
- historical_view,
891
- summary_view,
892
- summary_display,
893
- detail_view,
894
- time_series_failure_rates,
895
- time_series_amd_tests,
896
- time_series_nvidia_tests,
897
- time_series_amd_model_plot,
898
- time_series_nvidia_model_plot,
899
- time_series_detail_view,
900
- selected_model_state,
901
- in_model_view_state,
902
- ],
903
  )
904
 
905
  # Summary button click handler
 
507
  def handle_summary_click(history_mode: bool):
508
  description = get_description_text()
509
  links = get_ci_links()
 
510
  if history_mode:
511
+ fr_plot, amd_plot, nvidia_plot = get_historical_summary_plots()
512
+ return (description, links, gr.update(visible=False), gr.update(visible=True),
513
+ gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
514
+ fr_plot, amd_plot, nvidia_plot, gr.update(visible=False), False, "")
 
 
 
 
 
 
 
 
 
 
 
515
  else:
516
  fig = create_summary_page(Ci_results.df, Ci_results.available_models)
517
+ return (description, links, gr.update(visible=True), gr.update(visible=False),
518
+ gr.update(visible=True), gr.update(value=fig, visible=True), gr.update(visible=False),
519
+ gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
520
+ gr.update(visible=False), False, "")
 
 
 
 
 
 
 
 
 
 
 
521
 
522
  summary_button.click(
523
  fn=handle_summary_click,
 
620
  )
621
 
622
  def handle_history_toggle(history_mode, last_selected_model, in_model_view):
623
+ # Helper to create visibility updates efficiently
624
+ hidden = gr.update(visible=False)
625
+ shown = gr.update(visible=True)
626
+ noop = gr.update()
627
+
628
  if history_mode:
629
+ if in_model_view and last_selected_model: # Show historical model detail
 
630
  amd_ts, nvidia_ts = show_time_series_model(last_selected_model)
631
+ return (hidden, shown, hidden, hidden, hidden, hidden, hidden, hidden,
632
+ amd_ts, nvidia_ts, shown, noop, noop, noop, True)
633
+ # Show historical summary
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634
  fr_plot, amd_plot, nvidia_plot = get_historical_summary_plots()
635
+ return (hidden, shown, hidden, hidden, hidden, fr_plot, amd_plot, nvidia_plot,
636
+ noop, noop, hidden, noop, noop, noop, False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637
  else:
638
+ # Switch to current mode
639
  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:
640
  fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, last_selected_model, Ci_results.all_historical_data)
641
+ return (shown, hidden, hidden, hidden, shown, hidden, hidden, hidden,
642
+ noop, noop, hidden, fig, amd_txt, nvidia_txt, True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
643
  else:
644
  fig = create_summary_page(Ci_results.df, Ci_results.available_models)
645
+ return (shown, hidden, shown, gr.update(value=fig, visible=True), hidden,
646
+ hidden, hidden, hidden, noop, noop, hidden, noop, noop, noop, False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
647
 
648
  history_view_button.change(
649
  fn=handle_history_toggle,
 
679
 
680
  # Unified model click handler: respects History toggle
681
  def handle_model_click(selected_model: str, history_mode: bool):
682
+ noop, hidden, shown = gr.update(), gr.update(visible=False), gr.update(visible=True)
683
  if history_mode:
684
  amd_ts, nvidia_ts = show_time_series_model(selected_model)
685
+ return (noop, noop, noop, hidden, shown, hidden, hidden, hidden, hidden, hidden,
686
+ hidden, amd_ts, nvidia_ts, shown, selected_model, True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
687
  else:
688
  fig, amd_txt, nvidia_txt = plot_model_stats(Ci_results.df, selected_model, Ci_results.all_historical_data)
689
+ return (fig, amd_txt, nvidia_txt, shown, hidden, hidden, hidden, shown, noop, noop,
690
+ noop, noop, noop, hidden, selected_model, True)
691
+
692
+ # Define common outputs for model click handlers
693
+ model_click_outputs = [
694
+ plot_output, amd_failed_tests_output, nvidia_failed_tests_output,
695
+ current_view, historical_view, summary_view, summary_display, detail_view,
696
+ time_series_failure_rates, time_series_amd_tests, time_series_nvidia_tests,
697
+ time_series_amd_model_plot, time_series_nvidia_model_plot, time_series_detail_view,
698
+ selected_model_state, in_model_view_state,
699
+ ]
700
+
 
 
 
 
 
701
  # Wire up all model buttons
702
  for i, btn in enumerate(model_buttons):
703
  model_name = model_choices[i]
704
  btn.click(
705
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
706
  inputs=[history_view_button],
707
+ outputs=model_click_outputs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
708
  )
709
 
710
  # Wire up AMD failing model buttons
 
714
  btn.click(
715
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
716
  inputs=[history_view_button],
717
+ outputs=model_click_outputs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
718
  )
719
 
720
  # Wire up NVIDIA failing model buttons
 
724
  btn.click(
725
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
726
  inputs=[history_view_button],
727
+ outputs=model_click_outputs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
728
  )
729
 
730
  # Wire up both failures model buttons
 
734
  btn.click(
735
  fn=lambda history_mode, m=model_name: handle_model_click(m, history_mode),
736
  inputs=[history_view_button],
737
+ outputs=model_click_outputs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
738
  )
739
 
740
  # Summary button click handler
model_page.py CHANGED
@@ -1,19 +1,13 @@
1
  import matplotlib.pyplot as plt
2
  import pandas as pd
3
- from utils import generate_underlined_line
4
  from data import extract_model_data, find_failure_first_seen
5
 
6
  # Figure dimensions
7
  FIGURE_WIDTH_DUAL = 18
8
  FIGURE_HEIGHT_DUAL = 9
9
 
10
- # Colors
11
- COLORS = {
12
- 'passed': '#4CAF50', # Medium green
13
- 'failed': '#E53E3E', # More red
14
- 'skipped': '#FFD54F', # Medium yellow
15
- 'error': '#8B0000' # Dark red
16
- }
17
 
18
  # Styling constants
19
  BLACK = '#000000'
 
1
  import matplotlib.pyplot as plt
2
  import pandas as pd
3
+ from utils import generate_underlined_line, COLORS
4
  from data import extract_model_data, find_failure_first_seen
5
 
6
  # Figure dimensions
7
  FIGURE_WIDTH_DUAL = 18
8
  FIGURE_HEIGHT_DUAL = 9
9
 
10
+ # Colors imported from utils
 
 
 
 
 
 
11
 
12
  # Styling constants
13
  BLACK = '#000000'
summary_page.py CHANGED
@@ -1,6 +1,7 @@
1
  import matplotlib.pyplot as plt
2
  import pandas as pd
3
  from data import extract_model_data
 
4
 
5
  # Layout parameters
6
  COLUMNS = 3
@@ -22,14 +23,7 @@ VERTICAL_SPACING_RATIO = 0.2
22
  AMD_BAR_OFFSET = 0.25
23
  NVIDIA_BAR_OFFSET = 0.54
24
 
25
- # Colors
26
- COLORS = {
27
- 'passed': '#4CAF50',
28
- 'failed': '#E53E3E',
29
- 'skipped': '#FFD54F',
30
- 'error': '#8B0000',
31
- 'empty': "#5B5B5B"
32
- }
33
 
34
  # Font styling
35
  MODEL_NAME_FONT_SIZE = 16
 
1
  import matplotlib.pyplot as plt
2
  import pandas as pd
3
  from data import extract_model_data
4
+ from utils import COLORS
5
 
6
  # Layout parameters
7
  COLUMNS = 3
 
23
  AMD_BAR_OFFSET = 0.25
24
  NVIDIA_BAR_OFFSET = 0.54
25
 
26
+ # Colors imported from utils
 
 
 
 
 
 
 
27
 
28
  # Font styling
29
  MODEL_NAME_FONT_SIZE = 16
time_series_gradio.py CHANGED
@@ -2,19 +2,11 @@ import pandas as pd
2
  import numpy as np
3
  from datetime import datetime
4
  from data import extract_model_data
 
5
  import gradio as gr
6
  import plotly.express as px
7
  import plotly.graph_objects as go
8
 
9
- COLORS = {
10
- 'passed': '#4CAF50',
11
- 'failed': '#E53E3E',
12
- 'skipped': '#FFD54F',
13
- 'error': '#8B0000',
14
- 'amd': '#ED1C24',
15
- 'nvidia': '#76B900'
16
- }
17
-
18
  def get_time_series_summary_dfs(historical_df: pd.DataFrame) -> dict:
19
  daily_stats = []
20
  dates = sorted(historical_df['date'].unique())
 
2
  import numpy as np
3
  from datetime import datetime
4
  from data import extract_model_data
5
+ from utils import COLORS
6
  import gradio as gr
7
  import plotly.express as px
8
  import plotly.graph_objects as go
9
 
 
 
 
 
 
 
 
 
 
10
  def get_time_series_summary_dfs(historical_df: pd.DataFrame) -> dict:
11
  daily_stats = []
12
  dates = sorted(historical_df['date'].unique())
utils.py CHANGED
@@ -49,3 +49,15 @@ logger = setup_logger()
49
 
50
  def generate_underlined_line(text: str) -> str:
51
  return text + "\n" + "─" * len(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  def generate_underlined_line(text: str) -> str:
51
  return text + "\n" + "─" * len(text)
52
+
53
+
54
+ # Shared color scheme across all visualization modules
55
+ COLORS = {
56
+ 'passed': '#4CAF50',
57
+ 'failed': '#E53E3E',
58
+ 'skipped': '#FFD54F',
59
+ 'error': '#8B0000',
60
+ 'empty': '#5B5B5B',
61
+ 'amd': '#ED1C24',
62
+ 'nvidia': '#76B900'
63
+ }