File size: 1,384 Bytes
545c4d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
import json
from huggingface_hub import HfApi
import pandas as pd


def compute_df():
    api = HfApi()
    # download all files in https://huggingface.co/illuin-cde/baselines
    files = [
        f
        for f in api.list_repo_files("illuin-cde/baselines")
        if f.startswith("metrics")
    ]
    print(files)

    metrics = []
    for file in files:
        result_path = api.hf_hub_download("illuin-cde/baselines", filename=file)
        with open(result_path, "r") as f:
            dic = json.load(f)
            dic.update(dic["metrics"])
            del dic["metrics"]
            metrics.append(dic)

    df = pd.DataFrame(metrics)
    df = df[
        [
            "model",
            "dataset",
            "split",
            "is_contextual",
            "ndcg_at_1",
            "ndcg_at_5",
            "ndcg_at_10",
            "ndcg_at_100",
        ]
    ]
    df["model"] = df["model"].apply(lambda x: x.split("/")[-1])
    df["dataset"] = df["dataset"].apply(lambda x: x.split("/")[-1])
    # round all numeric columns
    df = df.round(3)

    # sort by ndcg_at_5
    df = df.sort_values("ndcg_at_5", ascending=False)

    # gradio display
    gradio_df = gr.Dataframe(df)
    return gradio_df


# refresh button and precompute
gr.Interface(
    fn=compute_df, title="Results Leaderboard", inputs=None, outputs="dataframe"
).launch()