evijit HF staff commited on
Commit
96da9bf
·
verified ·
1 Parent(s): 651de3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -55
app.py CHANGED
@@ -660,112 +660,120 @@ first_model = next(iter(models.values()))
660
  category_choices = list(first_model['scores'].keys())
661
 
662
  with gr.Blocks(css=css) as demo:
663
- gr.Markdown("# AI System Social Impact Dashboard")
664
-
665
- initial_df = create_leaderboard(category_choices)
666
 
667
  with gr.Row():
668
- tab_selection = gr.Radio(["Leaderboard", "Category Analysis", "Detailed Scorecard"],
669
- label="Select Tab", value="Leaderboard")
 
 
 
 
670
 
671
  with gr.Row():
672
- model_chooser = gr.Dropdown(choices=[""] + list(models.keys()),
673
- label="Select AI System for Details",
674
- value="",
675
- interactive=True, visible=False)
676
- model_multi_chooser = gr.Dropdown(choices=list(models.keys()),
677
- label="Select AI Systems for Comparison",
678
- value=[],
679
- multiselect=True,
680
- interactive=True,
681
- visible=False,
682
- info="Select one or more AI Systems")
683
-
684
- # Category filter now visible for all tabs
685
  category_filter = gr.CheckboxGroup(choices=category_choices,
686
  label="Filter Categories",
687
  value=category_choices)
688
 
689
  with gr.Column(visible=True) as leaderboard_tab:
 
690
  leaderboard_output = gr.DataFrame(
691
  value=initial_df,
692
  interactive=False,
693
- wrap=True,
694
- datatype=["markdown", "markdown", "markdown"] + ["markdown"] * (len(category_choices)+1) # Support markdown in all columns
695
  )
696
 
697
- with gr.Column(visible=False) as category_analysis_tab:
698
- # Initialize with empty plot
699
- initial_plot = create_category_chart([], category_choices)
700
- category_chart = gr.Plot(value=initial_plot)
701
 
702
  with gr.Column(visible=False) as detailed_scorecard_tab:
703
- model_metadata = gr.HTML()
704
  all_category_cards = gr.HTML()
705
  total_score = gr.Markdown()
706
 
707
- def update_dashboard(tab, selected_models, selected_model, selected_categories):
708
- # Default visibility states
709
  component_states = {
710
  "leaderboard": False,
711
- "category_chart": False,
712
  "detailed_scorecard": False,
713
- "model_chooser": False,
714
- "model_multi_chooser": False
715
  }
716
 
717
- # Initialize outputs with None
718
  outputs = {
719
  "leaderboard": None,
720
- "category_chart": None,
721
- "model_metadata": None,
722
  "category_cards": None,
723
  "total_score": None
724
  }
725
 
726
- # Update visibility based on selected tab
727
  if tab == "Leaderboard":
728
  component_states["leaderboard"] = True
729
  outputs["leaderboard"] = create_leaderboard(selected_categories)
730
 
731
- elif tab == "Category Analysis":
732
- component_states["category_chart"] = True
733
- component_states["model_multi_chooser"] = True
734
- if selected_models: # Only update chart if models are selected
735
- outputs["category_chart"] = create_category_chart(selected_models, selected_categories)
 
736
 
737
  elif tab == "Detailed Scorecard":
738
  component_states["detailed_scorecard"] = True
739
- component_states["model_chooser"] = True
740
- if selected_model:
741
- scorecard_updates = update_detailed_scorecard(selected_model, selected_categories)
742
- outputs["model_metadata"] = scorecard_updates[0]
743
  outputs["category_cards"] = scorecard_updates[1]
744
  outputs["total_score"] = scorecard_updates[2]
745
 
746
- # Return updates in the correct order
747
  return [
748
  gr.update(visible=component_states["leaderboard"]),
749
- gr.update(visible=component_states["category_chart"]),
750
  gr.update(visible=component_states["detailed_scorecard"]),
751
- gr.update(visible=component_states["model_chooser"]),
752
- gr.update(visible=component_states["model_multi_chooser"]),
753
  outputs["leaderboard"] if outputs["leaderboard"] is not None else gr.update(),
754
- outputs["category_chart"] if outputs["category_chart"] is not None else gr.update(),
755
- outputs["model_metadata"] if outputs["model_metadata"] is not None else gr.update(),
756
  outputs["category_cards"] if outputs["category_cards"] is not None else gr.update(),
757
  outputs["total_score"] if outputs["total_score"] is not None else gr.update()
758
  ]
759
 
760
  # Set up event handlers
761
- for component in [tab_selection, model_chooser, model_multi_chooser, category_filter]:
762
  component.change(
763
  fn=update_dashboard,
764
- inputs=[tab_selection, model_multi_chooser, model_chooser, category_filter],
765
- outputs=[leaderboard_tab, category_analysis_tab, detailed_scorecard_tab,
766
- model_chooser, model_multi_chooser,
767
- leaderboard_output, category_chart, model_metadata,
768
- all_category_cards, total_score]
 
 
 
 
 
 
769
  )
770
 
771
  # Launch the app
 
660
  category_choices = list(first_model['scores'].keys())
661
 
662
  with gr.Blocks(css=css) as demo:
663
+ gr.Markdown("# AI System Social Impact Scorecard Dashboard")
 
 
664
 
665
  with gr.Row():
666
+ tab_selection = gr.Radio(
667
+ # ["Leaderboard", "Category Analysis", "Detailed Scorecard"], # Original tabs
668
+ ["Leaderboard", "Detailed Scorecard"], # Current tabs
669
+ label="Select Tab",
670
+ value="Leaderboard"
671
+ )
672
 
673
  with gr.Row():
674
+ system_chooser = gr.Dropdown(choices=[""] + list(models.keys()),
675
+ label="Select AI System for Details",
676
+ value="",
677
+ interactive=True, visible=False)
678
+ # Commenting out multi-chooser for now
679
+ # system_multi_chooser = gr.Dropdown(choices=list(models.keys()),
680
+ # label="Select AI Systems for Comparison",
681
+ # value=[],
682
+ # multiselect=True,
683
+ # interactive=True,
684
+ # visible=False,
685
+ # info="Select one or more AI systems")
686
+
687
  category_filter = gr.CheckboxGroup(choices=category_choices,
688
  label="Filter Categories",
689
  value=category_choices)
690
 
691
  with gr.Column(visible=True) as leaderboard_tab:
692
+ initial_df = create_leaderboard(category_choices)
693
  leaderboard_output = gr.DataFrame(
694
  value=initial_df,
695
  interactive=False,
696
+ wrap=True
 
697
  )
698
 
699
+ # Commenting out category analysis tab for now
700
+ # with gr.Column(visible=False) as category_analysis_tab:
701
+ # initial_plot = create_category_chart([], category_choices)
702
+ # category_chart = gr.Plot(value=initial_plot)
703
 
704
  with gr.Column(visible=False) as detailed_scorecard_tab:
705
+ system_metadata = gr.HTML()
706
  all_category_cards = gr.HTML()
707
  total_score = gr.Markdown()
708
 
709
+ def update_dashboard(tab, selected_system, selected_categories):
710
+ # Original component states
711
  component_states = {
712
  "leaderboard": False,
713
+ # "category_chart": False, # Commented out
714
  "detailed_scorecard": False,
715
+ "system_chooser": False,
716
+ # "system_multi_chooser": False, # Commented out
717
  }
718
 
719
+ # Original outputs
720
  outputs = {
721
  "leaderboard": None,
722
+ # "category_chart": None, # Commented out
723
+ "system_metadata": None,
724
  "category_cards": None,
725
  "total_score": None
726
  }
727
 
 
728
  if tab == "Leaderboard":
729
  component_states["leaderboard"] = True
730
  outputs["leaderboard"] = create_leaderboard(selected_categories)
731
 
732
+ # Commenting out Category Analysis tab handling
733
+ # elif tab == "Category Analysis":
734
+ # component_states["category_chart"] = True
735
+ # component_states["system_multi_chooser"] = True
736
+ # if selected_systems:
737
+ # outputs["category_chart"] = create_category_chart(selected_systems, selected_categories)
738
 
739
  elif tab == "Detailed Scorecard":
740
  component_states["detailed_scorecard"] = True
741
+ component_states["system_chooser"] = True
742
+ if selected_system:
743
+ scorecard_updates = update_detailed_scorecard(selected_system, selected_categories)
744
+ outputs["system_metadata"] = scorecard_updates[0]
745
  outputs["category_cards"] = scorecard_updates[1]
746
  outputs["total_score"] = scorecard_updates[2]
747
 
748
+ # Return updates with commented out components removed
749
  return [
750
  gr.update(visible=component_states["leaderboard"]),
751
+ # gr.update(visible=component_states["category_chart"]), # Commented out
752
  gr.update(visible=component_states["detailed_scorecard"]),
753
+ gr.update(visible=component_states["system_chooser"]),
754
+ # gr.update(visible=component_states["system_multi_chooser"]), # Commented out
755
  outputs["leaderboard"] if outputs["leaderboard"] is not None else gr.update(),
756
+ # outputs["category_chart"] if outputs["category_chart"] is not None else gr.update(), # Commented out
757
+ outputs["system_metadata"] if outputs["system_metadata"] is not None else gr.update(),
758
  outputs["category_cards"] if outputs["category_cards"] is not None else gr.update(),
759
  outputs["total_score"] if outputs["total_score"] is not None else gr.update()
760
  ]
761
 
762
  # Set up event handlers
763
+ for component in [tab_selection, system_chooser, category_filter]: # Removed system_multi_chooser
764
  component.change(
765
  fn=update_dashboard,
766
+ inputs=[tab_selection, system_chooser, category_filter], # Removed system_multi_chooser
767
+ outputs=[leaderboard_tab,
768
+ # category_analysis_tab, # Commented out
769
+ detailed_scorecard_tab,
770
+ system_chooser,
771
+ # system_multi_chooser, # Commented out
772
+ leaderboard_output,
773
+ # category_chart, # Commented out
774
+ system_metadata,
775
+ all_category_cards,
776
+ total_score]
777
  )
778
 
779
  # Launch the app