pufanyi commited on
Commit
09c7b10
1 Parent(s): 95e674a

Refactor init_leaderboard function to handle multiple subsets and improve column selection and hiding

Browse files
Files changed (3) hide show
  1. app.py +15 -25
  2. src/display/utils.py +1 -0
  3. src/populate.py +3 -1
app.py CHANGED
@@ -3,6 +3,7 @@ from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
3
  import pandas as pd
4
  from apscheduler.schedulers.background import BackgroundScheduler
5
  from huggingface_hub import snapshot_download
 
6
 
7
  from src.about import (
8
  CITATION_BUTTON_LABEL,
@@ -67,37 +68,26 @@ except Exception:
67
  LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO)
68
 
69
 
70
- def init_leaderboard(dataframes):
71
  if dataframes is None or not dataframes:
72
  raise ValueError("Leaderboard data is empty or None.")
73
 
74
- def create_leaderboard(df):
75
- return Leaderboard(
76
- value=df,
77
- datatype=[c.type for c in fields(AutoEvalColumn)],
78
- select_columns=SelectColumns(
79
- default_selection=[c.name for c in fields(AutoEvalColumn) if c.displayed_by_default],
80
- cant_deselect=[c.name for c in fields(AutoEvalColumn) if c.never_hidden],
81
- label="Select Columns to Display:",
82
- ),
83
- search_columns=[AutoEvalColumn.model.name],
84
- hide_columns=[c.name for c in fields(AutoEvalColumn) if c.hidden],
85
- filter_columns=[],
86
- interactive=False,
87
- )
88
 
89
- subset_names = list(dataframes.keys())
90
- selected_subset = gr.Dropdown(choices=subset_names, label="Select Dataset Subset", value=subset_names[0])
91
-
92
- leaderboard = gr.Dynamic(create_leaderboard, inputs=[selected_subset], outputs="output")
93
- selected_subset.change(
94
- fn=lambda x: create_leaderboard(dataframes[x]),
95
- inputs=[selected_subset],
96
- outputs=leaderboard
 
 
 
 
97
  )
98
 
99
- return leaderboard
100
-
101
  demo = gr.Blocks(css=custom_css)
102
  with demo:
103
  gr.HTML(TITLE)
 
3
  import pandas as pd
4
  from apscheduler.schedulers.background import BackgroundScheduler
5
  from huggingface_hub import snapshot_download
6
+ # from fastchat.serve.monitor.monitor import build_leaderboard_tab, build_basic_stats_tab, basic_component_values, leader_component_values
7
 
8
  from src.about import (
9
  CITATION_BUTTON_LABEL,
 
68
  LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO)
69
 
70
 
71
+ def init_leaderboard(dataframes, subsets):
72
  if dataframes is None or not dataframes:
73
  raise ValueError("Leaderboard data is empty or None.")
74
 
75
+ selected_subset = gr.Dropdown(choices=subsets, label="Select Dataset Subset", value=subsets[0])
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
+ return Leaderboard(
78
+ value=dataframes,
79
+ datatype=[c.type for c in fields(AutoEvalColumn)],
80
+ select_columns=SelectColumns(
81
+ default_selection=[c.name for c in fields(AutoEvalColumn) if c.displayed_by_default],
82
+ cant_deselect=[c.name for c in fields(AutoEvalColumn) if c.never_hidden],
83
+ label="Select Columns to Display:",
84
+ ),
85
+ search_columns=[AutoEvalColumn.model.name],
86
+ hide_columns=[c.name for c in fields(AutoEvalColumn) if c.hidden],
87
+ filter_columns=[],
88
+ interactive=False,
89
  )
90
 
 
 
91
  demo = gr.Blocks(css=custom_css)
92
  with demo:
93
  gr.HTML(TITLE)
src/display/utils.py CHANGED
@@ -33,6 +33,7 @@ auto_eval_column_dict.append(
33
  auto_eval_column_dict.append(["Overall", ColumnContent, ColumnContent("Total", "number", True)])
34
  for task in Tasks:
35
  auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
 
36
 
37
  # We use make dataclass to dynamically fill the scores from Tasks
38
  AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
 
33
  auto_eval_column_dict.append(["Overall", ColumnContent, ColumnContent("Total", "number", True)])
34
  for task in Tasks:
35
  auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
36
+ auto_eval_column_dict.append(["Dataset Version", ColumnContent, ColumnContent("Dataset Version", "str", True)])
37
 
38
  # We use make dataclass to dynamically fill the scores from Tasks
39
  AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
src/populate.py CHANGED
@@ -18,5 +18,7 @@ def get_leaderboard_df(results_repo):
18
  subset_df = subset_df.sort_values(by="Total", ascending=False)
19
  subset_df = subset_df.round(2) # Round all numeric columns to two decimal places
20
  print(subset_df)
 
21
  subset_dfs[subset] = subset_df
22
- return subset_dfs
 
 
18
  subset_df = subset_df.sort_values(by="Total", ascending=False)
19
  subset_df = subset_df.round(2) # Round all numeric columns to two decimal places
20
  print(subset_df)
21
+ subset_df["Dataset Version"] = [subset] * len(subset_df)
22
  subset_dfs[subset] = subset_df
23
+ df = pd.concat(subset_dfs.values())
24
+ return df, subset_dfs.keys()