results / app.py
manu's picture
Update app.py
4b0eff3 verified
raw
history blame
1.27 kB
import gradio as gr
import json
from huggingface_hub import HfApi
import pandas as pd
import os
def compute_df():
api = HfApi(token=os.environ.get("HF_API_KEY"))
# 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()