pufanyi commited on
Commit
f5f1257
β€’
1 Parent(s): a885ec8

Refactor init_leaderboard function to update data outputs to dataframe and improve dropdown UI

Browse files
Files changed (2) hide show
  1. app.py +10 -5
  2. src/display/utils.py +3 -1
app.py CHANGED
@@ -71,9 +71,11 @@ except Exception:
71
 
72
  LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO)
73
 
 
74
  def GET_DEFAULT_TEXTBOX():
75
  return gr.Textbox("", placeholder="πŸ” Search Models... [press enter]", label="Filter Models by Name")
76
 
 
77
  def GET_DEFAULT_CHECKBOX():
78
  print("Choices:", [c.name for c in fields(AutoEvalColumn) if not c.hidden])
79
  return gr.CheckboxGroup(
@@ -86,7 +88,6 @@ def GET_DEFAULT_CHECKBOX():
86
  def init_leaderboard(dataframes):
87
  subsets = list(dataframes.keys())
88
 
89
-
90
  with gr.Row():
91
  selected_subset = gr.Dropdown(choices=subsets, label="Select Dataset Subset", value=subsets[-1])
92
  research_textbox = GET_DEFAULT_TEXTBOX()
@@ -102,7 +103,7 @@ def init_leaderboard(dataframes):
102
  global LEADERBOARD_DF
103
  LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO)
104
  default_columns = [c.name for c in fields(AutoEvalColumn) if c.displayed_by_default]
105
-
106
  return update_data(subset, None, default_columns), GET_DEFAULT_TEXTBOX(), GET_DEFAULT_CHECKBOX()
107
 
108
  def update_data(subset, search_term, selected_columns):
@@ -111,11 +112,15 @@ def init_leaderboard(dataframes):
111
  print("Selected Columns:", selected_columns)
112
  filtered_data = dataframes[subset]
113
  if search_term:
114
- filtered_data = filtered_data[dataframes[subset]['Model Name'].str.contains(search_term, case=False)]
115
- selected_data.sort_values(by="Total", ascending=False, inplace=True)
116
  selected_columns = [c.name for c in fields(AutoEvalColumn) if c.name in selected_columns]
117
  selected_data = filtered_data[selected_columns]
118
- return gr.DataFrame(selected_data, type="pandas", datatype=[c.type for c in fields(AutoEvalColumn) if c.name in selected_columns])
 
 
 
 
119
 
120
  with gr.Row():
121
  refresh_button = gr.Button("Refresh")
 
71
 
72
  LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO)
73
 
74
+
75
  def GET_DEFAULT_TEXTBOX():
76
  return gr.Textbox("", placeholder="πŸ” Search Models... [press enter]", label="Filter Models by Name")
77
 
78
+
79
  def GET_DEFAULT_CHECKBOX():
80
  print("Choices:", [c.name for c in fields(AutoEvalColumn) if not c.hidden])
81
  return gr.CheckboxGroup(
 
88
  def init_leaderboard(dataframes):
89
  subsets = list(dataframes.keys())
90
 
 
91
  with gr.Row():
92
  selected_subset = gr.Dropdown(choices=subsets, label="Select Dataset Subset", value=subsets[-1])
93
  research_textbox = GET_DEFAULT_TEXTBOX()
 
103
  global LEADERBOARD_DF
104
  LEADERBOARD_DF = get_leaderboard_df(RESULTS_REPO)
105
  default_columns = [c.name for c in fields(AutoEvalColumn) if c.displayed_by_default]
106
+
107
  return update_data(subset, None, default_columns), GET_DEFAULT_TEXTBOX(), GET_DEFAULT_CHECKBOX()
108
 
109
  def update_data(subset, search_term, selected_columns):
 
112
  print("Selected Columns:", selected_columns)
113
  filtered_data = dataframes[subset]
114
  if search_term:
115
+ filtered_data = filtered_data[dataframes[subset]["Model Name"].str.contains(search_term, case=False)]
116
+ filtered_data = filtered_data.sort_values(by="Total", ascending=False, inplace=True)
117
  selected_columns = [c.name for c in fields(AutoEvalColumn) if c.name in selected_columns]
118
  selected_data = filtered_data[selected_columns]
119
+ return gr.DataFrame(
120
+ selected_data,
121
+ type="pandas",
122
+ datatype=[c.type for c in fields(AutoEvalColumn) if c.name in selected_columns],
123
+ )
124
 
125
  with gr.Row():
126
  refresh_button = gr.Button("Refresh")
src/display/utils.py CHANGED
@@ -26,7 +26,9 @@ class ColumnContent:
26
  auto_eval_column_dict = []
27
  # Init
28
  # auto_eval_column_dict.append(["model_type_symbol", ColumnContent, ColumnContent("T", "str", True, never_hidden=True)])
29
- auto_eval_column_dict.append(["model", ColumnContent, ColumnContent("Model Name", "str", True, True, never_hidden=True)])
 
 
30
  # Scores
31
  auto_eval_column_dict.append(["Overall", ColumnContent, ColumnContent("Total", "number", True)])
32
  for task in Tasks:
 
26
  auto_eval_column_dict = []
27
  # Init
28
  # auto_eval_column_dict.append(["model_type_symbol", ColumnContent, ColumnContent("T", "str", True, never_hidden=True)])
29
+ auto_eval_column_dict.append(
30
+ ["model", ColumnContent, ColumnContent("Model Name", "str", True, True, never_hidden=True)]
31
+ )
32
  # Scores
33
  auto_eval_column_dict.append(["Overall", ColumnContent, ColumnContent("Total", "number", True)])
34
  for task in Tasks: