albertvillanova HF staff commited on
Commit
25557b5
1 Parent(s): da06368

Add app file

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+ import pandas as pd
5
+ from huggingface_hub import HfFileSystem
6
+
7
+
8
+ RESULTS_DATASET_ID = "datasets/open-llm-leaderboard/results"
9
+
10
+
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
+ def render_result_1(result_path, results):
29
+ result = load_result(result_path)
30
+ return pd.concat([result, results.iloc[:, [0, 2]].set_index("Parameters")], axis=1).reset_index()
31
+
32
+
33
+ def render_result_2(result_path, results):
34
+ result = load_result(result_path)
35
+ return pd.concat([results.iloc[:, [0, 1]].set_index("Parameters"), result], axis=1).reset_index()
36
+
37
+
38
+ if __name__ == "__main__":
39
+ results = fetch_results()
40
+
41
+ with gr.Blocks(fill_height=True) as demo:
42
+ gr.HTML("<h1 style='text-align: center;'>Compare Results of the 🤗 Open LLM Leaderboard</h1>")
43
+ gr.HTML("<h3 style='text-align: center;'>Select 2 results to load and compare</h3>")
44
+
45
+ with gr.Row():
46
+ with gr.Column():
47
+ result_path_1 = gr.Dropdown(choices=results, label="Results")
48
+ load_btn_1 = gr.Button("Load")
49
+ with gr.Column():
50
+ result_path_2 = gr.Dropdown(choices=results, label="Results")
51
+ load_btn_2 = gr.Button("Load")
52
+
53
+ with gr.Row():
54
+ compared_results = gr.Dataframe(
55
+ label="Results",
56
+ headers=["Parameters", "Result-1", "Result-2"],
57
+ interactive=False,
58
+ column_widths=["30%", "30%", "30%"],
59
+ wrap=True
60
+ )
61
+
62
+ load_btn_1.click(
63
+ fn=render_result_1,
64
+ inputs=[result_path_1, compared_results],
65
+ outputs=compared_results,
66
+ )
67
+ load_btn_2.click(
68
+ fn=render_result_2,
69
+ inputs=[result_path_2, compared_results],
70
+ outputs=compared_results,
71
+ )
72
+
73
+ demo.launch()