File size: 1,339 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
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-v2")
        if f.startswith("metrics")
    ]
    print(files)

    metrics = []
    cols = ["model", "is_contextual"]
    for file in files:
        result_path = api.hf_hub_download("illuin-cde/baselines-v2", filename=file)
        with open(result_path, "r") as f:
            dic = json.load(f)
            metrics_cur = dic["metrics"]
            for k, v in metrics_cur.items():
                dic.update({k: v["ndcg_at_5"]})
                cols.append(k)
            del dic["metrics"]
            metrics.append(dic)

    df = pd.DataFrame(metrics)
    df = df[cols]
    df["model"] = df["model"].apply(lambda x: x.split("/")[-1])
    # round all numeric columns
    # avg all numeric columns
    df["avg"] = df.iloc[:, 2:].mean(axis=1)
    df = df.round(3)

    # sort by ndcg_at_5
    df = df.sort_values(by="avg", 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()