andreybavt ZeroCommand commited on
Commit
5ad7125
1 Parent(s): 8b223ff

GSK-2690-return-empty-df-when-no-dataset (#81)

Browse files

- return empty df when loading leaderboard dataset error (125e9f35a21808a3f302d39bbd05fd836930bf53)
- update the dataframe after every load from leaderboard dataset (4ecd715c49bb7e3a4daaf306c4c35a603990f253)
- clean log with logger.ingo (e842ae735c237b2a6049e74b5011e885f9f6cefe)


Co-authored-by: zcy <ZeroCommand@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app_leaderboard.py +12 -6
app_leaderboard.py CHANGED
@@ -2,6 +2,7 @@ import logging
2
 
3
  import datasets
4
  import gradio as gr
 
5
 
6
  from fetch_utils import (check_dataset_and_get_config,
7
  check_dataset_and_get_split)
@@ -24,7 +25,7 @@ def get_records_from_dataset_repo(dataset_id):
24
  logger.warning(
25
  f"Failed to load dataset {dataset_id} with config {dataset_config}: {e}"
26
  )
27
- return None
28
 
29
 
30
  def get_model_ids(ds):
@@ -73,10 +74,6 @@ def get_display_df(df):
73
  )
74
  return display_df
75
 
76
- def update_leaderboard_records():
77
- logger.info("Updating leaderboard records")
78
- leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
79
-
80
  def get_demo(leaderboard_tab):
81
  logger.info("Loading leaderboard records")
82
  leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
@@ -119,7 +116,15 @@ def get_demo(leaderboard_tab):
119
  with gr.Row():
120
  leaderboard_df = gr.DataFrame(display_df, datatype=types, interactive=False)
121
 
122
- leaderboard_tab.select(fn=update_leaderboard_records)
 
 
 
 
 
 
 
 
123
 
124
  @gr.on(
125
  triggers=[
@@ -132,6 +137,7 @@ def get_demo(leaderboard_tab):
132
  outputs=[leaderboard_df],
133
  )
134
  def filter_table(model_id, dataset_id, columns, task):
 
135
  records = leaderboard.records
136
  # filter the table based on task
137
  df = records[(records["task"] == task)]
 
2
 
3
  import datasets
4
  import gradio as gr
5
+ import pandas as pd
6
 
7
  from fetch_utils import (check_dataset_and_get_config,
8
  check_dataset_and_get_split)
 
25
  logger.warning(
26
  f"Failed to load dataset {dataset_id} with config {dataset_config}: {e}"
27
  )
28
+ return pd.DataFrame()
29
 
30
 
31
  def get_model_ids(ds):
 
74
  )
75
  return display_df
76
 
 
 
 
 
77
  def get_demo(leaderboard_tab):
78
  logger.info("Loading leaderboard records")
79
  leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
 
116
  with gr.Row():
117
  leaderboard_df = gr.DataFrame(display_df, datatype=types, interactive=False)
118
 
119
+ def update_leaderboard_records(model_id, dataset_id, columns, task):
120
+ logger.info("Updating leaderboard records")
121
+ leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
122
+ return filter_table(model_id, dataset_id, columns, task)
123
+
124
+ leaderboard_tab.select(
125
+ fn=update_leaderboard_records,
126
+ inputs=[model_select, dataset_select, columns_select, task_select],
127
+ outputs=[leaderboard_df])
128
 
129
  @gr.on(
130
  triggers=[
 
137
  outputs=[leaderboard_df],
138
  )
139
  def filter_table(model_id, dataset_id, columns, task):
140
+ logger.info("Filtering leaderboard records")
141
  records = leaderboard.records
142
  # filter the table based on task
143
  df = records[(records["task"] == task)]