File size: 2,100 Bytes
34fdd66
3f476f1
34fdd66
 
 
4b0eff3
34fdd66
c4d23b9
 
 
 
34fdd66
 
 
f4a7ca2
34fdd66
8533f16
34fdd66
3a6bb2d
34fdd66
1c2e62d
34fdd66
 
2ec8f31
 
3a6bb2d
 
8533f16
 
50d1af7
90bbe69
 
34fdd66
 
 
 
8533f16
08621fe
34fdd66
8533f16
04bcc90
34fdd66
 
 
8533f16
34fdd66
 
12fde76
 
 
34fdd66
3f476f1
 
 
 
 
 
c1d8a9a
3f476f1
12fde76
3f476f1
34fdd66
3f476f1
 
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
57
58
59
60
61
62
63
64
import gradio as gr
import re
import json
from huggingface_hub import HfApi
import pandas as pd
import os

token = os.getenv('HF_API_KEY')
print(f"The token is {token}")
api = HfApi(token=token)


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

    metrics = []
    cols = ["model", "is_contextual", "pooling"]
    for file in files:
        result_path = api.hf_hub_download("illuin-cde/baselines-v3", filename=file)
        with open(result_path, "r") as f:
            dic = json.load(f)
            if dic["is_contextual"] not in ["multi", "single", "hybrid"]:
                continue
            # prefix =  dic.get("pooling", "default")
            dic["model"] = dic.get("model").split("/")[-1] # + "-" + prefix
            metrics_cur = dic["metrics"]
            for k, v in metrics_cur.items():
                dic.update({k: v["ndcg_at_10"]})
                if k not in cols:
                    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[:, 3:].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
    return df


gradio_df = compute_df()

def refresh(model_query_regex):
    if not model_query_regex:
        return gradio_df
    
    # filter the dataframe based on regex
    return gr.Dataframe(gradio_df[gradio_df["model"].str.contains(model_query_regex, flags=re.IGNORECASE, regex=True)])

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