albertvillanova HF Staff commited on
Commit
2908a66
·
verified ·
1 Parent(s): 7f37223

Use latest result per model

Browse files
Files changed (1) hide show
  1. app.py +38 -20
app.py CHANGED
@@ -11,32 +11,50 @@ RESULTS_DATASET_ID = "datasets/open-llm-leaderboard/results"
11
  fs = HfFileSystem()
12
 
13
 
14
- def fetch_results():
15
- files = fs.glob(f"{RESULTS_DATASET_ID}/**/**/*.json")
16
- results = [file[len(RESULTS_DATASET_ID) + 1:] for file in files]
17
- return results
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  def load_result(result_path) -> pd.DataFrame:
21
- with fs.open(f"{RESULTS_DATASET_ID}/{result_path}", "r") as f:
22
  data = json.load(f)
23
  model_name = data.get("model_name", "Model")
24
  df = pd.json_normalize([data])
25
  return df.iloc[0].rename_axis("Parameters").rename(model_name).to_frame().reset_index()
26
 
27
 
28
- if __name__ == "__main__":
29
- results = fetch_results()
30
-
31
- with gr.Blocks(fill_height=True) as demo:
32
- gr.HTML("<h1 style='text-align: center;'>Results of the 🤗 Open LLM Leaderboard</h1>")
33
- gr.HTML("<h3 style='text-align: center;'>Select a result to load</h3>")
34
- result_path = gr.Dropdown(choices=results, label="Results")
35
- load_btn = gr.Button("Load")
36
- result = gr.Dataframe(label="Result")
37
- load_btn.click(
38
- fn=load_result,
39
- inputs=result_path,
40
- outputs=result,
41
- )
42
- demo.launch()
 
 
 
 
 
 
11
  fs = HfFileSystem()
12
 
13
 
14
+ def fetch_result_paths():
15
+ paths = fs.glob(f"{RESULTS_DATASET_ID}/**/**/*.json")
16
+ return paths
17
+
18
+
19
+ def filter_latest_result_path_per_model(paths):
20
+ from collections import defaultdict
21
+
22
+ d = defaultdict(list)
23
+ for path in paths:
24
+ model_id, _ = path[len(RESULTS_DATASET_ID) +1:].rsplit("/", 1)
25
+ d[model_id].append(path)
26
+ return {model_id: max(paths) for model_id, paths in d.items()}
27
+
28
+
29
+ def get_result_path_from_model(model_id, result_path_per_model):
30
+ return result_path_per_model[model_id]
31
 
32
 
33
  def load_result(result_path) -> pd.DataFrame:
34
+ with fs.open(result_path, "r") as f:
35
  data = json.load(f)
36
  model_name = data.get("model_name", "Model")
37
  df = pd.json_normalize([data])
38
  return df.iloc[0].rename_axis("Parameters").rename(model_name).to_frame().reset_index()
39
 
40
 
41
+ def render_result(model_id):
42
+ result_path = get_result_path_from_model(model_id, latest_result_path_per_model)
43
+ return load_result(result_path)
44
+
45
+
46
+ # if __name__ == "__main__":
47
+ latest_result_path_per_model = filter_latest_result_path_per_model(fetch_result_paths())
48
+
49
+ with gr.Blocks(fill_height=True) as demo:
50
+ gr.HTML("<h1 style='text-align: center;'>Results of the 🤗 Open LLM Leaderboard</h1>")
51
+ gr.HTML("<h3 style='text-align: center;'>Select a result to load</h3>")
52
+ model_id = gr.Dropdown(choices=list(latest_result_path_per_model.keys()), label="Results")
53
+ load_btn = gr.Button("Load")
54
+ result = gr.Dataframe(label="Result")
55
+ load_btn.click(
56
+ fn=render_result,
57
+ inputs=model_id,
58
+ outputs=result,
59
+ )
60
+ demo.launch()