File size: 2,867 Bytes
1ac264d
 
 
 
 
 
 
 
 
726831f
1ac264d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
726831f
1ac264d
 
 
 
726831f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ac264d
 
 
 
726831f
 
 
 
1ac264d
 
 
726831f
 
 
 
0f0fe92
726831f
1ac264d
 
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import json
from pathlib import Path

import gradio as gr
import pandas as pd

TITLE = 'EASI Leaderboard'
DATA_PATH = Path("leaderboard.csv")
META_PATH = Path("benchmark.json")
DISPLAY_TEXT_LIMIT = 96

df = pd.read_csv(DATA_PATH)
if "score" in df.columns:
    df["score"] = pd.to_numeric(df["score"], errors="coerce")

meta = {}
if META_PATH.exists():
    try:
        meta = json.loads(META_PATH.read_text(encoding="utf-8"))
    except Exception:
        meta = {}


def metric_narrative():
    likely_metrics = (((meta.get("analysis") or {}).get("likely_metrics")) or [])
    if likely_metrics:
        return (
            "This benchmark is ranked by the primary `score` column (descending). "
            "Reported benchmark metrics include: " + ", ".join([str(x) for x in likely_metrics]) + "."
        )

    known_non_metrics = {
        "model_name",
        "score",
        "source_title",
        "source_url",
        "notes",
    }
    metric_like = [c for c in df.columns if c not in known_non_metrics]
    if metric_like:
        return (
            "This benchmark is ranked by the primary `score` column (descending). "
            "Table columns include: " + ", ".join(metric_like) + "."
        )
    return "This benchmark is ranked by the primary `score` column (descending)."


def render(query, top_k):
    x = df.copy()
    if query.strip():
        x = x[x["model_name"].astype(str).str.contains(query.strip(), case=False, na=False)]
    if "score" in x.columns:
        x = x.sort_values(by=["score"], ascending=False, na_position="last")
    x = x.head(int(top_k)).reset_index(drop=True)
    x = compact_for_display(x)
    x.insert(0, "display_rank", x.index + 1)
    return x


def compact_for_display(frame):
    out = frame.copy()
    for col in out.columns:
        if out[col].dtype != object:
            continue
        out[col] = out[col].apply(truncate_cell)
    return out


def truncate_cell(value):
    if value is None:
        return value
    text = str(value)
    if len(text) <= DISPLAY_TEXT_LIMIT:
        return text
    return text[: DISPLAY_TEXT_LIMIT - 3] + "..."


with gr.Blocks(title=TITLE) as demo:
    gr.Markdown(f"# {TITLE}")
    gr.Markdown(metric_narrative())
    gr.Markdown(f"Rows: {len(df)}")
    with gr.Row():
        gr.DownloadButton("Download CSV", value=str(DATA_PATH))
        if Path("leaderboard.json").exists():
            gr.DownloadButton("Download JSON", value="leaderboard.json")
    with gr.Row():
        query = gr.Textbox(label="Model contains")
        top_k = gr.Slider(minimum=5, maximum=500, step=1, value=100, label="Top K")
    table = gr.Dataframe(
        value=render("", 100),
        interactive=False,
        wrap=False,
        row_count=(20, "fixed"),
    )
    query.change(render, [query, top_k], table)
    top_k.change(render, [query, top_k], table)

demo.launch()