pufanyi commited on
Commit
dd084c3
1 Parent(s): 88477a4

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

Browse files
Files changed (1) hide show
  1. app.py +30 -17
app.py CHANGED
@@ -64,26 +64,39 @@ except Exception:
64
  restart_space()
65
 
66
 
67
- LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO, EVAL_RESULTS_PATH, "2024-06")
68
 
69
 
70
- def init_leaderboard(dataframe):
71
- if dataframe is None or dataframe.empty:
72
- raise ValueError("Leaderboard DataFrame is empty or None.")
73
- return Leaderboard(
74
- value=dataframe,
75
- datatype=[c.type for c in fields(AutoEvalColumn)],
76
- select_columns=SelectColumns(
77
- default_selection=[c.name for c in fields(AutoEvalColumn) if c.displayed_by_default],
78
- cant_deselect=[c.name for c in fields(AutoEvalColumn) if c.never_hidden],
79
- label="Select Columns to Display:",
80
- ),
81
- search_columns=[AutoEvalColumn.model.name],
82
- hide_columns=[c.name for c in fields(AutoEvalColumn) if c.hidden],
83
- filter_columns=[],
84
- interactive=False,
 
 
 
 
 
 
 
 
 
 
 
 
85
  )
86
-
 
87
 
88
  demo = gr.Blocks(css=custom_css)
89
  with demo:
 
64
  restart_space()
65
 
66
 
67
+ LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO, EVAL_RESULTS_PATH)
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: