albertvillanova HF Staff commited on
Commit
f8be00e
·
verified ·
1 Parent(s): b09a5e0

Use latest result per model

Browse files
Files changed (1) hide show
  1. app.py +49 -31
app.py CHANGED
@@ -10,41 +10,59 @@ RESULTS_DATASET_ID = "datasets/open-llm-leaderboard/results"
10
  fs = HfFileSystem()
11
 
12
 
13
- def fetch_results():
14
- files = fs.glob(f"{RESULTS_DATASET_ID}/**/**/*.json")
15
- results = [file[len(RESULTS_DATASET_ID) +1:] for file in files]
16
- return results
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
 
19
  def load_result(result_path) -> dict:
20
- with fs.open(f"{RESULTS_DATASET_ID}/{result_path}", "r") as f:
21
  data = json.load(f)
22
  return data
23
 
24
 
25
- if __name__ == "__main__":
26
- results = fetch_results()
27
-
28
- with gr.Blocks() as demo:
29
- gr.HTML("<h1 style='text-align: center;'>Compare Results of the 🤗 Open LLM Leaderboard</h1>")
30
- gr.HTML("<h3 style='text-align: center;'>Select 2 results to load and compare</h3>")
31
- with gr.Row():
32
- with gr.Column():
33
- result_path_1 = gr.Dropdown(choices=results, label="Results")
34
- load_btn_1 = gr.Button("Load")
35
- result_1 = gr.JSON(label="Result")
36
- load_btn_1.click(
37
- fn=load_result,
38
- inputs=result_path_1,
39
- outputs=result_1,
40
- )
41
- with gr.Column():
42
- result_path_2 = gr.Dropdown(choices=results, label="Results")
43
- load_btn_2 = gr.Button("Load")
44
- result_2 = gr.JSON(label="Result")
45
- load_btn_2.click(
46
- fn=load_result,
47
- inputs=result_path_2,
48
- outputs=result_2,
49
- )
50
- demo.launch()
 
 
 
 
 
 
10
  fs = HfFileSystem()
11
 
12
 
13
+ def fetch_result_paths():
14
+ paths = fs.glob(f"{RESULTS_DATASET_ID}/**/**/*.json")
15
+ return paths
16
+
17
+
18
+ def filter_latest_result_path_per_model(paths):
19
+ from collections import defaultdict
20
+
21
+ d = defaultdict(list)
22
+ for path in paths:
23
+ model_id, _ = path[len(RESULTS_DATASET_ID) +1:].rsplit("/", 1)
24
+ d[model_id].append(path)
25
+ return {model_id: max(paths) for model_id, paths in d.items()}
26
+
27
+
28
+ def get_result_path_from_model(model_id, result_path_per_model):
29
+ return result_path_per_model[model_id]
30
 
31
 
32
  def load_result(result_path) -> dict:
33
+ with fs.open(result_path, "r") as f:
34
  data = json.load(f)
35
  return data
36
 
37
 
38
+ def render_result(model_id):
39
+ result_path = get_result_path_from_model(model_id, latest_result_path_per_model)
40
+ return load_result(result_path)
41
+
42
+
43
+ # if __name__ == "__main__":
44
+ latest_result_path_per_model = filter_latest_result_path_per_model(fetch_result_paths())
45
+
46
+ with gr.Blocks() as demo:
47
+ gr.HTML("<h1 style='text-align: center;'>Compare Results of the 🤗 Open LLM Leaderboard</h1>")
48
+ gr.HTML("<h3 style='text-align: center;'>Select 2 results to load and compare</h3>")
49
+ with gr.Row():
50
+ with gr.Column():
51
+ model_id_1 = gr.Dropdown(choices=list(latest_result_path_per_model.keys()), label="Results")
52
+ load_btn_1 = gr.Button("Load")
53
+ result_1 = gr.JSON(label="Result")
54
+ load_btn_1.click(
55
+ fn=render_result,
56
+ inputs=model_id_1,
57
+ outputs=result_1,
58
+ )
59
+ with gr.Column():
60
+ model_id_2 = gr.Dropdown(choices=list(latest_result_path_per_model.keys()), label="Results")
61
+ load_btn_2 = gr.Button("Load")
62
+ result_2 = gr.JSON(label="Result")
63
+ load_btn_2.click(
64
+ fn=render_result,
65
+ inputs=model_id_2,
66
+ outputs=result_2,
67
+ )
68
+ demo.launch()