leaderboard page reload on select to pull the latest dataset

#66
Files changed (2) hide show
  1. app.py +3 -1
  2. app_leaderboard.py +7 -5
app.py CHANGED
@@ -11,11 +11,13 @@ try:
11
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="green")) as demo:
12
  with gr.Tab("Text Classification"):
13
  get_demo_text_classification()
14
- with gr.Tab("Leaderboard"):
15
  get_demo_leaderboard()
16
  with gr.Tab("Logs(Debug)"):
17
  get_demo_debug()
18
 
 
 
19
  start_process_run_job()
20
 
21
  demo.queue(max_size=1000)
 
11
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="green")) as demo:
12
  with gr.Tab("Text Classification"):
13
  get_demo_text_classification()
14
+ with gr.Tab("Leaderboard") as leaderboard_tab:
15
  get_demo_leaderboard()
16
  with gr.Tab("Logs(Debug)"):
17
  get_demo_debug()
18
 
19
+ leaderboard_tab.select(fn=get_demo_leaderboard)
20
+
21
  start_process_run_job()
22
 
23
  demo.queue(max_size=1000)
app_leaderboard.py CHANGED
@@ -7,25 +7,26 @@ from fetch_utils import (check_dataset_and_get_config,
7
  check_dataset_and_get_split)
8
 
9
  import leaderboard
 
10
 
11
  def get_records_from_dataset_repo(dataset_id):
12
  dataset_config = check_dataset_and_get_config(dataset_id)
13
 
14
- logging.info(f"Dataset {dataset_id} has configs {dataset_config}")
15
  dataset_split = check_dataset_and_get_split(dataset_id, dataset_config[0])
16
- logging.info(f"Dataset {dataset_id} has splits {dataset_split}")
17
 
18
  try:
19
  ds = datasets.load_dataset(dataset_id, dataset_config[0])[dataset_split[0]]
20
  df = ds.to_pandas()
21
  return df
22
  except Exception as e:
23
- logging.warning(
24
  f"Failed to load dataset {dataset_id} with config {dataset_config}: {e}"
25
  )
26
  return None
27
 
28
-
29
  def get_model_ids(ds):
30
  logging.info(f"Dataset {ds} column names: {ds['model_id']}")
31
  models = ds["model_id"].tolist()
@@ -74,6 +75,7 @@ def get_display_df(df):
74
 
75
 
76
  def get_demo():
 
77
  leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
78
  records = leaderboard.records
79
 
@@ -138,4 +140,4 @@ def get_demo():
138
  df = df[columns]
139
  types = get_types(df)
140
  display_df = get_display_df(df)
141
- return gr.update(value=display_df, datatype=types, interactive=False)
 
7
  check_dataset_and_get_split)
8
 
9
  import leaderboard
10
+ logger = logging.getLogger(__name__)
11
 
12
  def get_records_from_dataset_repo(dataset_id):
13
  dataset_config = check_dataset_and_get_config(dataset_id)
14
 
15
+ logger.info(f"Dataset {dataset_id} has configs {dataset_config}")
16
  dataset_split = check_dataset_and_get_split(dataset_id, dataset_config[0])
17
+ logger.info(f"Dataset {dataset_id} has splits {dataset_split}")
18
 
19
  try:
20
  ds = datasets.load_dataset(dataset_id, dataset_config[0])[dataset_split[0]]
21
  df = ds.to_pandas()
22
  return df
23
  except Exception as e:
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):
31
  logging.info(f"Dataset {ds} column names: {ds['model_id']}")
32
  models = ds["model_id"].tolist()
 
75
 
76
 
77
  def get_demo():
78
+ logger.info("Loading leaderboard records")
79
  leaderboard.records = get_records_from_dataset_repo(leaderboard.LEADERBOARD)
80
  records = leaderboard.records
81
 
 
140
  df = df[columns]
141
  types = get_types(df)
142
  display_df = get_display_df(df)
143
+ return gr.update(value=display_df, datatype=types, interactive=False)