manu commited on
Commit
34fdd66
·
verified ·
1 Parent(s): 72436d6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from huggingface_hub import HfApi
4
+ import pandas as pd
5
+
6
+
7
+ def compute_df():
8
+ api = HfApi()
9
+ # download all files in https://huggingface.co/illuin-cde/baselines
10
+ files = [f for f in api.list_repo_files("illuin-cde/baselines") if f.startswith("metrics")]
11
+ print(files)
12
+
13
+ metrics = []
14
+ for file in files:
15
+ result_path = api.hf_hub_download("illuin-cde/baselines", filename=file)
16
+ with open(result_path, "r") as f:
17
+ dic = json.load(f)
18
+ dic.update(dic["metrics"])
19
+ del dic["metrics"]
20
+ metrics.append(dic)
21
+
22
+ df = pd.DataFrame(metrics)
23
+ df = df[["model", "dataset", "split", "is_contextual", "ndcg_at_1", "ndcg_at_5", "ndcg_at_10", "ndcg_at_100"]]
24
+ df["model"] = df["model"].apply(lambda x: x.split("/")[-1])
25
+ df["dataset"] = df["dataset"].apply(lambda x: x.split("/")[-1])
26
+ # round all numeric columns
27
+ df = df.round(3)
28
+
29
+ # sort by ndcg_at_5
30
+ df = df.sort_values("ndcg_at_5", ascending=False)
31
+
32
+ # gradio display
33
+ gradio_df = gr.Dataframe(df)
34
+ return gradio_df
35
+
36
+ # refresh button and precompute
37
+ gr.Interface(fn=compute_df, title="Results Leaderboard", inputs=None, outputs="dataframe").launch()