Spaces:
Sleeping
Sleeping
Download app.py from sqlll/BenchTemplate: direct link, hf CLI and curl.
- Browser
- Download file 41.7 kB
-
https://huggingface.co/spaces/sqlll/BenchTemplate/resolve/main/app.py
- Command line
-
hf download hf://spaces/sqlll/BenchTemplate/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sqlll/BenchTemplate/resolve/main/app.py
41.7 kB
from __future__ import annotations
from html import escape
from pathlib import Path
import gradio as gr
import pandas as pd
BASE_DIR = Path(__file__).resolve().parent
DATA_DIR = BASE_DIR / "data"
VIDEO_CANDIDATES = [
DATA_DIR / "video_examples.csv",
BASE_DIR / "video_examples.csv",
]
LEADERBOARD_CANDIDATES = [
DATA_DIR / "eval_results.csv",
DATA_DIR / "leaderboard.csv",
DATA_DIR / "results.csv",
BASE_DIR / "eval_results.csv",
BASE_DIR / "leaderboard.csv",
BASE_DIR / "results.csv",
]
def find_existing_csv(candidates: list[Path]) -> Path | None:
for path in candidates:
if path.exists():
return path
common_names = {"eval_results.csv", "leaderboard.csv", "results.csv", "video_examples.csv"}
for path in BASE_DIR.rglob("*.csv"):
if path.name in common_names:
for candidate in candidates:
if candidate.name == path.name:
return path
return None
def safe_read_csv(path: Path | None) -> pd.DataFrame:
if path is None or not path.exists():
return pd.DataFrame()
return pd.read_csv(path)
def normalize_text(value) -> str:
if pd.isna(value):
return ""
return str(value)
def resolve_media_path(value: str) -> str | None:
value = normalize_text(value).strip()
if not value:
return None
candidate = Path(value)
if candidate.is_absolute() and candidate.exists():
return str(candidate)
for prefix in (BASE_DIR, DATA_DIR):
maybe = prefix / value
if maybe.exists():
return str(maybe)
return value
VIDEO_EXAMPLES_PATH = find_existing_csv(VIDEO_CANDIDATES)
EVAL_RESULTS_PATH = find_existing_csv(LEADERBOARD_CANDIDATES)
video_examples_df = safe_read_csv(VIDEO_EXAMPLES_PATH)
eval_results_df = safe_read_csv(EVAL_RESULTS_PATH)
CUSTOM_CSS = """
:root{
--bg:#f5f7fb;
--panel:#ffffff;
--panel-soft:rgba(255,255,255,.82);
--line:#e7edf6;
--line-strong:#d7e1ef;
--text:#0f172a;
--muted:#64748b;
--navy:#0f172a;
--slate:#1e293b;
--indigo:#4f46e5;
--violet:#7c3aed;
--cyan:#0891b2;
--teal:#0f766e;
--green:#15803d;
--rose:#e11d48;
--amber:#d97706;
--green-soft:#eefcf3;
--rose-soft:#fff1f4;
--indigo-soft:#eef2ff;
--teal-soft:#ecfeff;
--shadow:0 22px 60px rgba(15,23,42,.08);
--shadow-soft:0 10px 28px rgba(15,23,42,.05);
--radius-xl:34px;
--radius-lg:24px;
--radius-md:18px;
}
html,body,.gradio-container,gradio-app{
background:
radial-gradient(1000px 420px at 50% -8%, rgba(255,255,255,.92) 0%, rgba(245,247,251,0) 58%),
linear-gradient(180deg,#f8fbff 0%,#f5f7fb 52%,#f4f6fb 100%) !important;
}
body,.gradio-container{ color:var(--text); }
.gradio-container{
max-width:none !important;
padding:0 !important;
}
#page_shell{
width:min(1320px, calc(100vw - 36px));
margin:0 auto !important;
padding:28px 0 44px !important;
}
.masthead{ display:none; }
.masthead-title, .masthead-sub, .masthead-badge{ display:none; }
.section-kicker{
display:flex;
align-items:center;
gap:10px;
font-size:12px;
line-height:1;
text-transform:uppercase;
letter-spacing:.18em;
font-weight:900;
}
.section-kicker .dot{
width:10px;
height:10px;
border-radius:999px;
}
.section-heading{
margin-top:12px;
font-size:30px;
line-height:1.08;
font-weight:950;
letter-spacing:-.04em;
}
.section-desc{
margin-top:10px;
font-size:14px;
line-height:1.65;
font-weight:600;
color:rgba(255,255,255,.78);
}
.section-desc.light{ color:var(--muted); }
#leaderboard_wrap{ margin-bottom:28px; }
.leaderboard-stage{
position:relative;
overflow:hidden;
border-radius:38px;
background:
radial-gradient(920px 320px at 10% 0%, rgba(99,102,241,.12) 0%, rgba(99,102,241,0) 56%),
radial-gradient(860px 320px at 100% 0%, rgba(14,165,233,.10) 0%, rgba(14,165,233,0) 50%),
linear-gradient(180deg,#ffffff 0%, #f7faff 54%, #f3f7ff 100%);
border:1px solid #dfe7f4;
box-shadow:0 24px 58px rgba(15,23,42,.08);
}
.leaderboard-stage::before{
content:"";
position:absolute;
inset:0;
background:
linear-gradient(120deg, rgba(255,255,255,.26), rgba(255,255,255,0) 34%),
linear-gradient(0deg, rgba(255,255,255,.18), rgba(255,255,255,0));
pointer-events:none;
}
.lb-top{
position:relative;
padding:28px 28px 22px;
display:grid;
grid-template-columns:minmax(0,1.15fr) minmax(360px,.95fr);
gap:24px;
align-items:end;
}
.lb-kicker{ color:var(--indigo); }
.lb-kicker .dot{
background:linear-gradient(135deg,#4f46e5,#0ea5e9);
box-shadow:0 0 0 7px rgba(79,70,229,.10);
}
.lb-title{
color:var(--navy);
}
.lb-desc{
color:#475569;
}
.lb-stats{
display:grid;
grid-template-columns:repeat(3, minmax(0,1fr));
gap:12px;
}
.lb-stat{
border-radius:22px;
padding:16px 16px 14px;
background:rgba(255,255,255,.88);
border:1px solid #e0e8f5;
backdrop-filter:blur(14px);
box-shadow:var(--shadow-soft);
}
.lb-stat-label{
font-size:11px;
line-height:1;
letter-spacing:.14em;
text-transform:uppercase;
font-weight:900;
color:#7b8aa3;
}
.lb-stat-value{
margin-top:10px;
color:var(--navy);
font-size:28px;
line-height:1;
font-weight:950;
letter-spacing:-.04em;
}
.lb-stat-sub{
margin-top:8px;
font-size:12px;
line-height:1.4;
font-weight:700;
color:#64748b;
}
.podium-row{
position:relative;
display:grid;
grid-template-columns:repeat(3, minmax(0,1fr));
gap:12px;
padding:0 28px 16px;
}
.podium-card{
display:flex;
align-items:center;
justify-content:space-between;
gap:14px;
border-radius:22px;
padding:14px 16px;
background:rgba(255,255,255,.92);
border:1px solid #e4ebf6;
box-shadow:var(--shadow-soft);
min-height:0;
}
.podium-card.top1{
background:linear-gradient(180deg, #f7f7ff 0%, #ffffff 100%);
border-color:#cfd4ff;
}
.podium-card.top2{
background:linear-gradient(180deg, #f3fdff 0%, #ffffff 100%);
border-color:#bcecf2;
}
.podium-card.top3{
background:linear-gradient(180deg, #fff9ef 0%, #ffffff 100%);
border-color:#fde3a7;
}
.podium-left{
display:flex;
align-items:center;
gap:12px;
min-width:0;
}
.podium-rank{
display:inline-flex;
align-items:center;
justify-content:center;
width:38px;
height:38px;
border-radius:12px;
font-size:13px;
font-weight:950;
background:#eef2f7;
color:#334155;
flex:0 0 auto;
}
.podium-card.top1 .podium-rank{
background:#eef2ff;
color:#4338ca;
}
.podium-card.top2 .podium-rank{
background:#ecfeff;
color:#0f766e;
}
.podium-card.top3 .podium-rank{
background:#fffbeb;
color:#b45309;
}
.podium-model{
color:var(--navy);
font-size:16px;
line-height:1.25;
font-weight:950;
letter-spacing:-.02em;
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
}
.podium-metric{
display:inline-flex;
align-items:center;
justify-content:center;
border-radius:999px;
padding:8px 12px;
background:#eef4ff;
border:1px solid #dbeafe;
color:#1d4ed8;
font-size:12px;
font-weight:900;
flex:0 0 auto;
}
.lb-table-shell{
position:relative;
margin:8px 18px 20px;
border-radius:30px;
overflow:hidden;
background:
linear-gradient(180deg, rgba(255,255,255,.78) 0%, rgba(250,252,255,.86) 100%);
border:none;
box-shadow:none;
}
.lb-table-head{
display:flex;
justify-content:space-between;
align-items:center;
gap:18px;
padding:18px 22px 10px;
background:transparent;
border-bottom:none;
}
.lb-table-title{
font-size:18px;
color:var(--navy);
font-weight:950;
letter-spacing:-.025em;
}
.lb-table-meta{
display:flex;
gap:10px;
flex-wrap:wrap;
justify-content:flex-end;
}
.meta-pill{
display:inline-flex;
align-items:center;
justify-content:center;
border-radius:999px;
padding:8px 12px;
background:rgba(248,251,255,.9);
border:none;
color:#64748b;
font-size:12px;
font-weight:850;
box-shadow:0 4px 12px rgba(15,23,42,.04);
}
.benchmark-table-wrap{
padding:14px 16px 18px;
overflow-x:auto;
}
.benchmark-table{
width:100%;
min-width:980px;
border-collapse:separate;
border-spacing:0 8px;
}
.benchmark-table thead th{
position:sticky;
top:0;
z-index:1;
padding:14px 14px 16px;
background:transparent;
font-size:13px;
line-height:1.2;
letter-spacing:.04em;
color:#475569;
font-weight:950;
text-align:center;
}
.benchmark-table thead th:first-child{
text-align:left;
font-size:15px;
}
.benchmark-table tbody tr.group-row td{
padding:14px 14px 8px;
text-align:center;
background:transparent;
color:#64748b;
font-size:12px;
line-height:1.2;
font-weight:950;
text-transform:uppercase;
letter-spacing:.12em;
}
.benchmark-table tbody tr.data-row{
transition:transform .16s ease, filter .16s ease;
transform-origin:center;
}
.benchmark-table tbody tr.data-row td{
padding:15px 14px;
background:rgba(255,255,255,.78);
font-size:14px;
line-height:1.45;
font-weight:700;
color:#243247;
text-align:center;
transition:background .16s ease;
border:none !important;
box-shadow:none !important;
}
.benchmark-table tbody tr.data-row td:first-child{
text-align:left;
border-top-left-radius:18px;
border-bottom-left-radius:18px;
}
.benchmark-table tbody tr.data-row td:last-child{
border-top-right-radius:18px;
border-bottom-right-radius:18px;
}
.benchmark-table tbody tr.data-row:hover{
transform:scale(1.012);
filter:drop-shadow(0 10px 20px rgba(15,23,42,.08));
}
.benchmark-table tbody tr.data-row:hover td{
background:#f8fbff;
}
.model-cell{
display:flex;
flex-direction:column;
gap:4px;
}
.model-main{
color:var(--navy);
font-size:15px;
line-height:1.32;
font-weight:950;
letter-spacing:-.02em;
}
.model-sub{
color:#64748b;
font-size:12px;
line-height:1.4;
font-weight:700;
}
.metric-value{
display:inline-block;
min-width:54px;
font-variant-numeric:tabular-nums;
}
.metric-value.best-up{
color:#1d4ed8;
font-weight:950;
}
.metric-value.best-down{
color:#b45309;
font-weight:950;
}
.metric-value.muted{
color:#94a3b8;
}
.rank-badge{
display:inline-flex;
align-items:center;
justify-content:center;
min-width:44px;
height:44px;
border-radius:15px;
font-size:14px;
font-weight:950;
background:#eef2f7;
color:#334155;
border:1px solid #dbe5f2;
}
.rank-badge.top1{ background:#eef2ff; color:#4338ca; border-color:#c7d2fe; }
.rank-badge.top2{ background:#ecfeff; color:#0f766e; border-color:#bae6fd; }
.rank-badge.top3{ background:#fffbeb; color:#b45309; border-color:#fde68a; }
.model-cell{ display:flex; flex-direction:column; gap:4px; }
.model-main{
font-size:16px;
line-height:1.28;
font-weight:950;
color:var(--text);
}
.model-note{
font-size:12px;
line-height:1.45;
color:#64748b;
font-weight:700;
}
.metric-main{
font-size:18px;
font-weight:950;
color:var(--navy);
}
.score-pill{
display:inline-flex;
align-items:center;
justify-content:center;
min-width:84px;
border-radius:999px;
padding:8px 12px;
background:#eef4ff;
border:1px solid #dbeafe;
color:#1d4ed8;
font-size:13px;
font-weight:950;
}
.case-shell{
position:relative;
overflow:hidden;
border-radius:38px;
background:
radial-gradient(820px 280px at 100% 0%, rgba(16,185,129,.08) 0%, rgba(16,185,129,0) 52%),
radial-gradient(720px 240px at 0% 0%, rgba(59,130,246,.08) 0%, rgba(59,130,246,0) 54%),
linear-gradient(180deg,#ffffff 0%, #fcfdff 100%);
border:1px solid var(--line);
box-shadow:var(--shadow);
padding:24px 24px 20px;
}
.case-topband{
display:grid;
grid-template-columns:minmax(0,1fr) minmax(280px, 420px);
gap:18px;
align-items:end;
margin-bottom:18px;
}
.case-kicker{ color:var(--indigo); }
.case-kicker .dot{
background:linear-gradient(135deg,#4f46e5,#06b6d4);
box-shadow:0 0 0 7px rgba(79,70,229,.10);
}
.case-toolbar{
padding:0;
}
#sample_selector > label,
#sample_selector .caption-wrap{
display:none !important;
}
#sample_selector .wrap,
#sample_selector .inner,
#sample_selector .dropdown,
#sample_selector .secondary-wrap{
border-radius:20px !important;
border:1px solid var(--line-strong) !important;
background:rgba(255,255,255,.95) !important;
box-shadow:var(--shadow-soft);
}
#sample_selector input,
#sample_selector .single-select{
font-weight:850;
color:var(--text) !important;
}
.summary-band{
display:grid;
grid-template-columns:repeat(4, minmax(0,1fr));
gap:14px;
margin-bottom:18px;
}
.summary-card{
border-radius:22px;
padding:16px 18px;
background:rgba(255,255,255,.88);
border:1px solid var(--line);
box-shadow:var(--shadow-soft);
}
.summary-label{
font-size:11px;
line-height:1;
color:#8b97ac;
font-weight:900;
text-transform:uppercase;
letter-spacing:.14em;
margin-bottom:10px;
}
.summary-value{
font-size:30px;
line-height:1;
font-weight:950;
letter-spacing:-.04em;
}
.summary-value.correct{ color:var(--green); }
.summary-value.incorrect{ color:var(--rose); }
.summary-value.accuracy{ color:var(--indigo); }
.summary-value.neutral{ color:var(--navy); }
.summary-sub{
margin-top:8px;
color:var(--muted);
font-size:13px;
line-height:1.45;
font-weight:650;
}
#hero_row{
gap:18px;
align-items:stretch !important;
margin-bottom:18px;
}
.surface-card{
border-radius:30px;
background:var(--panel-soft);
border:1px solid var(--line);
box-shadow:var(--shadow-soft);
overflow:hidden;
}
.video-shell{
padding:16px;
background:linear-gradient(180deg,#fbfcff 0%, #ffffff 100%);
}
#main_video{
border-radius:24px;
overflow:hidden;
}
#main_video video{
border-radius:24px !important;
background:#030712 !important;
min-height:430px;
}
.hero-side{ display:flex; flex-direction:column; gap:18px; }
.qa-card{
padding:26px 26px 22px;
background:linear-gradient(180deg,#ffffff 0%, #fcfdff 100%);
}
.eyebrow{
color:#7c8aa2;
font-size:11px;
font-weight:900;
letter-spacing:.16em;
text-transform:uppercase;
margin-bottom:12px;
}
.title-row{
display:flex;
align-items:center;
gap:10px;
flex-wrap:wrap;
margin-bottom:18px;
}
.pill{
display:inline-flex;
align-items:center;
gap:6px;
border-radius:999px;
padding:8px 12px;
font-size:12px;
line-height:1;
font-weight:850;
}
.pill.primary{ background:var(--indigo-soft); color:var(--indigo); }
.pill.soft{ background:#f8fafc; color:var(--muted); border:1px solid var(--line); }
.pill.correct{ background:var(--green-soft); color:var(--green); }
.pill.incorrect{ background:var(--rose-soft); color:var(--rose); }
.question-text{
font-size:32px;
line-height:1.34;
font-weight:950;
letter-spacing:-.04em;
color:var(--text);
}
.reference-wrap{ margin-top:20px; }
.reference-details{
border:1px solid var(--line);
border-radius:22px;
background:#fafcff;
overflow:hidden;
}
.reference-summary{
list-style:none;
cursor:pointer;
padding:16px 18px;
font-size:13px;
font-weight:850;
color:var(--navy);
display:flex;
align-items:center;
justify-content:space-between;
}
.reference-summary::-webkit-details-marker{ display:none; }
.reference-summary::after{
content:"+";
color:var(--muted);
font-size:18px;
line-height:1;
}
.reference-details[open] .reference-summary::after{ content:"–"; }
.reference-body{
padding:0 18px 18px;
font-size:15px;
line-height:1.72;
font-weight:650;
color:#334155;
}
.responses-shell{
position:relative;
margin-top:4px;
border-radius:30px;
background:linear-gradient(180deg, rgba(247,249,253,.92) 0%, rgba(255,255,255,.96) 100%);
border:1px solid var(--line);
box-shadow:var(--shadow-soft);
padding:20px;
}
.board-header{
display:flex;
justify-content:space-between;
align-items:flex-end;
gap:14px;
flex-wrap:wrap;
margin-bottom:16px;
}
.board-title{
font-size:22px;
line-height:1.1;
font-weight:950;
letter-spacing:-.03em;
color:var(--navy);
}
.board-sub{ display:none; }
.legend{
display:flex;
gap:8px;
flex-wrap:wrap;
}
.legend-chip{
display:inline-flex;
align-items:center;
gap:8px;
border-radius:999px;
border:1px solid var(--line);
background:#fff;
padding:8px 12px;
font-size:12px;
color:var(--muted);
font-weight:850;
}
.legend-chip .swatch{
width:10px;
height:10px;
border-radius:999px;
}
.response-grid{
display:grid;
grid-template-columns:repeat(12, minmax(0,1fr));
gap:18px;
}
.response-card{
grid-column:span 4;
position:relative;
min-height:320px;
border-radius:28px;
overflow:hidden;
background:linear-gradient(180deg,#fff 0%, #f9fbff 100%);
border:1px solid var(--line);
box-shadow:var(--shadow-soft);
}
.response-card::before{
content:"";
position:absolute;
inset:0 0 auto 0;
height:6px;
background:var(--accent, var(--indigo));
}
.response-card.correct{
background:linear-gradient(180deg,#ffffff 0%, #f8fff9 100%);
border-color:#d7efdd;
}
.response-card.incorrect{
background:linear-gradient(180deg,#ffffff 0%, #fff8fa 100%);
border-color:#ffd8e2;
}
.response-card.unknown{
background:linear-gradient(180deg,#ffffff 0%, #fbfcff 100%);
}
.response-inner{
padding:18px 18px 20px;
display:flex;
flex-direction:column;
gap:14px;
height:100%;
}
.response-head{
display:flex;
justify-content:space-between;
gap:12px;
align-items:flex-start;
}
.model-meta{
display:flex;
gap:12px;
min-width:0;
}
.model-index{
width:42px;
height:42px;
min-width:42px;
border-radius:15px;
display:inline-flex;
align-items:center;
justify-content:center;
color:#fff;
font-size:13px;
font-weight:950;
box-shadow:inset 0 0 0 1px rgba(255,255,255,.14);
background:#64748b;
}
.model-name{
font-size:18px;
line-height:1.34;
font-weight:950;
color:var(--text);
word-break:break-word;
}
.model-sub{
color:var(--muted);
font-size:12px;
font-weight:700;
margin-top:4px;
}
.status-badge{
display:inline-flex;
align-items:center;
border-radius:999px;
padding:8px 11px;
font-size:11px;
line-height:1;
font-weight:950;
letter-spacing:.08em;
text-transform:uppercase;
white-space:nowrap;
}
.status-badge.correct{ background:var(--green-soft); color:var(--green); }
.status-badge.incorrect{ background:var(--rose-soft); color:var(--rose); }
.status-badge.unknown{ background:#f1f5f9; color:#475569; }
.response-text{
color:#1e293b;
font-size:15px;
line-height:1.72;
white-space:pre-wrap;
flex:1;
}
.note-box{
border-radius:18px;
padding:12px 13px;
border:1px solid var(--line);
background:#f8fbff;
}
.note-box.correct{ background:#f7fff9; border-color:#d7efdd; }
.note-box.incorrect{ background:#fff8fa; border-color:#ffd8e2; }
.note-label{
font-size:10px;
font-weight:950;
letter-spacing:.14em;
text-transform:uppercase;
color:var(--muted);
margin-bottom:6px;
}
.note-text{
color:#475569;
font-size:13px;
line-height:1.58;
font-weight:650;
}
.empty-card{
border-radius:28px;
padding:40px 24px;
text-align:center;
background:rgba(255,255,255,.84);
border:1px dashed var(--line-strong);
color:var(--muted);
font-size:14px;
font-weight:700;
}
@media (max-width: 1180px){
#page_shell{ width:min(1180px, calc(100vw - 26px)); }
.lb-top{ grid-template-columns:1fr; }
.case-topband{ grid-template-columns:1fr; }
.summary-band{ grid-template-columns:repeat(2, minmax(0,1fr)); }
.response-card{ grid-column:span 6; }
}
@media (max-width: 980px){
.podium-row{ grid-template-columns:1fr; }
}
@media (max-width: 880px){
#page_shell{
width:calc(100vw - 16px);
padding:18px 0 28px !important;
}
.masthead{ flex-direction:column; align-items:flex-start; }
.masthead-title{ font-size:32px; }
.leaderboard-stage, .case-shell{ border-radius:30px; }
.podium-row{ grid-template-columns:1fr; }
.summary-band{ grid-template-columns:1fr 1fr; gap:12px; }
#main_video video{ min-height:280px; }
.question-text{ font-size:24px; }
.response-card{ grid-column:span 12; min-height:0; }
}
@media (max-width: 640px){
.summary-band{ grid-template-columns:1fr; }
.lb-stats{ grid-template-columns:1fr; }
.masthead-title{ font-size:28px; }
.section-heading{ font-size:24px; }
.lb-title, .board-title{ font-size:20px; }
}
"""
MODEL_COLORS = [
"#64748b",
"#64748b",
"#64748b",
"#64748b",
"#64748b",
"#64748b",
"#64748b",
"#64748b",
]
def status_info(raw_value: str):
value = normalize_text(raw_value).strip().lower()
if value in {"1", "true", "yes", "correct", "right", "✓"}:
return "correct", "Correct", 2
if value in {"0", "false", "no", "incorrect", "wrong", "✗"}:
return "incorrect", "Incorrect", 1
return "unknown", "Unlabeled", 0
def to_float(value):
try:
if pd.isna(value):
return None
return float(value)
except Exception:
return None
def fmt_metric(value, digits=1, suffix=""):
v = to_float(value)
if v is None:
return "—"
return f"{v:.{digits}f}{suffix}"
def get_video_labels() -> list[str]:
if video_examples_df.empty:
return ["No example"]
labels = []
for i, (_, row) in enumerate(video_examples_df.iterrows(), start=1):
title = normalize_text(row.get("title", "")).strip()
ex_id = normalize_text(row.get("id", "")).strip()
if title and ex_id:
labels.append(f"{ex_id} · {title}")
elif title:
labels.append(title)
elif ex_id:
labels.append(ex_id)
else:
labels.append(f"Example {i}")
return labels
VIDEO_LABELS = get_video_labels()
def count_statuses(row: pd.Series) -> tuple[int, int, int]:
correct = incorrect = unknown = 0
for idx in range(1, 9):
if not normalize_text(row.get(f"model_{idx}_name", "")).strip() and not normalize_text(row.get(f"model_{idx}_response", "")).strip():
continue
status_class, _, _ = status_info(row.get(f"model_{idx}_correct", ""))
if status_class == "correct":
correct += 1
elif status_class == "incorrect":
incorrect += 1
else:
unknown += 1
return correct, incorrect, unknown
def _resolve_column_by_aliases(df: pd.DataFrame, aliases: list[str]) -> str | None:
lowered = {}
for col in df.columns:
key = normalize_text(col).strip().lower().replace("-", "_").replace(" ", "_").replace("@", "").replace("/", "_")
lowered[key] = col
for alias in aliases:
key = alias.strip().lower().replace("-", "_").replace(" ", "_").replace("@", "").replace("/", "_")
if key in lowered:
return lowered[key]
return None
def _metric_specs(df: pd.DataFrame) -> list[dict]:
candidates = [
{"aliases": ["sr_a", "sra", "sr_a_up"], "label": "SR@A↑", "direction": "up"},
{"aliases": ["sr_ab", "srab", "sr_ab_up"], "label": "SR@AB↑", "direction": "up"},
{"aliases": ["sr_c", "src", "sr_c_down"], "label": "SR@C↓", "direction": "down"},
{"aliases": ["sr_d", "srd", "sr_d_down"], "label": "SR@D↓", "direction": "down"},
{"aliases": ["sr_e", "sre", "sr_e_down"], "label": "SR@E↓", "direction": "down"},
{"aliases": ["open_set", "openset", "open_set_score"], "label": "Open-set↑", "direction": "up"},
{"aliases": ["accuracy", "acc"], "label": "Accuracy↑", "direction": "up"},
{"aliases": ["f1"], "label": "F1↑", "direction": "up"},
{"aliases": ["avg_score", "avg", "score"], "label": "Avg Score↑", "direction": "up"},
]
specs = []
for cand in candidates:
col = _resolve_column_by_aliases(df, cand["aliases"])
if col is not None:
specs.append({"col": col, "label": cand["label"], "direction": cand["direction"]})
return specs
def _best_metric_values(df: pd.DataFrame, specs: list[dict]) -> dict[str, float | None]:
bests = {}
for spec in specs:
series = pd.to_numeric(df[spec["col"]], errors="coerce")
if series.notna().any():
bests[spec["col"]] = float(series.min() if spec["direction"] == "down" else series.max())
else:
bests[spec["col"]] = None
return bests
def _format_metric(raw) -> str:
num = to_float(raw)
if num is None:
text = normalize_text(raw).strip()
return text or "—"
return f"{num:.2f}"
def render_masthead() -> str:
return ""
def render_leaderboard() -> str:
if eval_results_df.empty:
searched = [str(p.relative_to(BASE_DIR)) if p.is_relative_to(BASE_DIR) else str(p) for p in LEADERBOARD_CANDIDATES]
return f"""
<div class="leaderboard-stage">
<div class="lb-top">
<div>
<div class="section-kicker lb-kicker"><span class="dot"></span><span>Leaderboard</span></div>
<div class="section-heading lb-title">Overall Benchmark Results</div>
<div class="section-desc lb-desc">No leaderboard file was found. Expected one of: {escape(', '.join(searched))}</div>
</div>
</div>
</div>
"""
df = eval_results_df.copy()
model_col = _resolve_column_by_aliases(df, ["model", "name"]) or df.columns[0]
group_col = _resolve_column_by_aliases(df, ["group", "section", "category", "family"])
org_col = _resolve_column_by_aliases(df, ["organization", "org", "institution"])
note_col = _resolve_column_by_aliases(df, ["notes", "note"])
link_col = _resolve_column_by_aliases(df, ["link", "url", "href"])
metric_specs = _metric_specs(df)
if not metric_specs:
fallback = [c for c in df.columns if c not in {model_col, group_col, org_col, note_col, link_col}]
metric_specs = [{"col": c, "label": c.replace("_", " ").title(), "direction": "up"} for c in fallback[:5]]
primary = next((m for m in metric_specs if m["direction"] == "up"), metric_specs[0])
sort_series = pd.to_numeric(df[primary["col"]], errors="coerce")
sort_df = df.assign(__sort=sort_series)
sort_df = sort_df.sort_values("__sort", ascending=(primary["direction"] == "down"), na_position="last").reset_index(drop=True)
top_model = escape(normalize_text(sort_df.iloc[0].get(model_col, "")).strip() or "—")
best_score = _format_metric(sort_df.iloc[0].get(primary["col"], ""))
top_acc_col = _resolve_column_by_aliases(df, ["accuracy", "acc"])
top_acc = _format_metric(sort_df.iloc[0].get(top_acc_col, "")) if top_acc_col else "—"
stat_metric_name = primary["label"].replace("↑", "").replace("↓", "").strip()
podium_html = []
for i in range(min(3, len(sort_df))):
row = sort_df.iloc[i]
model = escape(normalize_text(row.get(model_col, "")).strip() or f"Model {i+1}")
main_metric = _format_metric(row.get(primary["col"], ""))
css = f"top{i+1}"
podium_html.append(
f"""
<div class="podium-card {css}">
<div class="podium-left">
<div class="podium-rank">#{i+1}</div>
<div class="podium-model">{model}</div>
</div>
<div class="podium-metric">{main_metric}</div>
</div>
"""
)
best_values = _best_metric_values(df, metric_specs)
header_cells = ['<th style="text-align:left;">Model</th>']
for spec in metric_specs:
header_cells.append(f'<th>{escape(spec["label"])}</th>')
body_rows = []
if group_col:
seen_groups = []
ordered_groups = []
for g in df[group_col].tolist():
key = normalize_text(g).strip() or "Ungrouped"
if key not in seen_groups:
seen_groups.append(key)
ordered_groups.append(key)
for group_name in ordered_groups:
group_df = df[df[group_col].fillna("").astype(str).str.strip().replace("", "Ungrouped") == group_name]
if group_df.empty:
continue
body_rows.append(f'<tr class="group-row"><td colspan="{1 + len(metric_specs)}">{escape(group_name)}</td></tr>')
for _, row in group_df.iterrows():
model = escape(normalize_text(row.get(model_col, "")).strip() or "—")
org = escape(normalize_text(row.get(org_col, "")).strip()) if org_col else ""
note = escape(normalize_text(row.get(note_col, "")).strip()) if note_col else ""
link = normalize_text(row.get(link_col, "")).strip() if link_col else ""
model_html = f"<a href='{escape(link)}' target='_blank' style='color:inherit; text-decoration:none;'>{model}</a>" if link else model
sub_lines = []
if org:
sub_lines.append(f'<div class="model-sub">{org}</div>')
if note:
sub_lines.append(f'<div class="model-sub">{note}</div>')
cells = [f'<td><div class="model-cell"><div class="model-main">{model_html}</div>{"".join(sub_lines)}</div></td>']
for spec in metric_specs:
display = _format_metric(row.get(spec["col"], ""))
num = to_float(row.get(spec["col"], ""))
best = best_values.get(spec["col"])
cls = "metric-value"
if num is None:
cls += " muted"
elif best is not None and abs(num - best) < 1e-9:
cls += " best-down" if spec["direction"] == "down" else " best-up"
cells.append(f'<td><span class="{cls}">{display}</span></td>')
body_rows.append(f'<tr class="data-row">{"".join(cells)}</tr>')
else:
body_rows.append(f'<tr class="group-row"><td colspan="{1 + len(metric_specs)}">All Models</td></tr>')
for _, row in sort_df.iterrows():
model = escape(normalize_text(row.get(model_col, "")).strip() or "—")
org = escape(normalize_text(row.get(org_col, "")).strip()) if org_col else ""
note = escape(normalize_text(row.get(note_col, "")).strip()) if note_col else ""
link = normalize_text(row.get(link_col, "")).strip() if link_col else ""
model_html = f"<a href='{escape(link)}' target='_blank' style='color:inherit; text-decoration:none;'>{model}</a>" if link else model
sub_lines = []
if org:
sub_lines.append(f'<div class="model-sub">{org}</div>')
if note:
sub_lines.append(f'<div class="model-sub">{note}</div>')
cells = [f'<td><div class="model-cell"><div class="model-main">{model_html}</div>{"".join(sub_lines)}</div></td>']
for spec in metric_specs:
display = _format_metric(row.get(spec["col"], ""))
num = to_float(row.get(spec["col"], ""))
best = best_values.get(spec["col"])
cls = "metric-value"
if num is None:
cls += " muted"
elif best is not None and abs(num - best) < 1e-9:
cls += " best-down" if spec["direction"] == "down" else " best-up"
cells.append(f'<td><span class="{cls}">{display}</span></td>')
body_rows.append(f'<tr class="data-row">{"".join(cells)}</tr>')
group_count = len(df[group_col].fillna("").astype(str).str.strip().replace("", "Ungrouped").drop_duplicates()) if group_col else 1
return f"""
<div class="leaderboard-stage">
<div class="lb-top">
<div>
<div class="section-kicker lb-kicker"><span class="dot"></span><span>Leaderboard</span></div>
<div class="section-heading lb-title">Overall Benchmark Results</div>
</div>
<div class="lb-stats">
<div class="lb-stat">
<div class="lb-stat-label">Models</div>
<div class="lb-stat-value">{len(df)}</div>
<div class="lb-stat-sub">{group_count} benchmark groups</div>
</div>
<div class="lb-stat">
<div class="lb-stat-label">Top Model</div>
<div class="lb-stat-value" style="font-size:18px; line-height:1.18;">{top_model}</div>
<div class="lb-stat-sub">Current leader</div>
</div>
<div class="lb-stat">
<div class="lb-stat-label">Best {stat_metric_name}</div>
<div class="lb-stat-value">{best_score}</div>
<div class="lb-stat-sub">Top accuracy {top_acc}</div>
</div>
</div>
</div>
<div class="podium-row">
{''.join(podium_html)}
</div>
<div class="lb-table-shell">
<div class="lb-table-head">
<div class="lb-table-title">Full Ranking</div>
<div class="lb-table-meta">
<span class="meta-pill">Grouped benchmark table</span>
<span class="meta-pill">{len(metric_specs)} metrics</span>
</div>
</div>
<div class="benchmark-table-wrap">
<table class="benchmark-table">
<thead>
<tr>
{''.join(header_cells)}
</tr>
</thead>
<tbody>
{''.join(body_rows)}
</tbody>
</table>
</div>
</div>
</div>
"""
def render_case_intro() -> str:
return """
<div>
<div class="section-kicker case-kicker"><span class="dot"></span><span>Case Study</span></div>
<div class="section-heading">Qualitative Video Example</div>
</div>
"""
def render_summary_band(row: pd.Series) -> str:
correct, incorrect, unknown = count_statuses(row)
total = max(correct + incorrect + unknown, 1)
labeled = correct + incorrect
accuracy = round(100 * correct / labeled) if labeled else 0
title = escape(normalize_text(row.get("title", "")).strip() or "Sample")
category = escape(normalize_text(row.get("category", "")).strip() or "—")
return f"""
<div class="summary-band">
<div class="summary-card">
<div class="summary-label">Sample</div>
<div class="summary-value neutral">{title}</div>
<div class="summary-sub">{category}</div>
</div>
<div class="summary-card">
<div class="summary-label">Correct</div>
<div class="summary-value correct">{correct}</div>
<div class="summary-sub">Models aligned with reference</div>
</div>
<div class="summary-card">
<div class="summary-label">Incorrect</div>
<div class="summary-value incorrect">{incorrect}</div>
<div class="summary-sub">Models missing this sample</div>
</div>
<div class="summary-card">
<div class="summary-label">Labeled Accuracy</div>
<div class="summary-value accuracy">{accuracy}%</div>
<div class="summary-sub">{labeled} / {total} responses labeled</div>
</div>
</div>
"""
def render_question_panel(row: pd.Series) -> str:
title = escape(normalize_text(row.get("title", "")).strip() or "Sample")
question = escape(normalize_text(row.get("question", "")).strip() or "")
ground_truth = escape(normalize_text(row.get("ground_truth", "")).strip() or "—")
split = escape(normalize_text(row.get("split", "")).strip() or "")
category = escape(normalize_text(row.get("category", "")).strip() or "")
correct, incorrect, unknown = count_statuses(row)
pills = [f'<span class="pill primary">{title}</span>']
if split:
pills.append(f'<span class="pill soft">{split}</span>')
if category:
pills.append(f'<span class="pill soft">{category}</span>')
if correct:
pills.append(f'<span class="pill correct">{correct} Correct</span>')
if incorrect:
pills.append(f'<span class="pill incorrect">{incorrect} Incorrect</span>')
if unknown:
pills.append(f'<span class="pill soft">{unknown} Unlabeled</span>')
return f"""
<div class="surface-card qa-card">
<div class="eyebrow">Video Question</div>
<div class="title-row">{''.join(pills)}</div>
<div class="question-text">{question}</div>
<div class="reference-wrap">
<details class="reference-details">
<summary class="reference-summary">Reference Answer</summary>
<div class="reference-body">{ground_truth}</div>
</details>
</div>
</div>
"""
def render_response_cards(row: pd.Series) -> str:
cards = []
rows = []
correct, incorrect, unknown = count_statuses(row)
total = correct + incorrect + unknown
for idx in range(1, 9):
model_name = normalize_text(row.get(f"model_{idx}_name", "")).strip()
response = normalize_text(row.get(f"model_{idx}_response", "")).strip()
if not model_name and not response:
continue
status_class, status_label, status_rank = status_info(row.get(f"model_{idx}_correct", ""))
rows.append({
"idx": idx,
"name": model_name or f"Model {idx}",
"response": response,
"status_class": status_class,
"status_label": status_label,
"status_rank": status_rank,
"note": normalize_text(row.get(f"model_{idx}_note", "")).strip(),
})
rows.sort(key=lambda x: (-x["status_rank"], x["idx"]))
for pos, item in enumerate(rows, start=1):
accent = MODEL_COLORS[(item["idx"] - 1) % len(MODEL_COLORS)]
note_html = ""
if item["note"]:
safe_note = escape(item["note"])
note_html = f"""
<div class="note-box {item['status_class']}">
<div class="note-label">Difference</div>
<div class="note-text">{safe_note}</div>
</div>
"""
cards.append(
f"""
<div class="response-card {item['status_class']}" style="--accent: {accent};">
<div class="response-inner">
<div class="response-head">
<div class="model-meta">
<div class="model-index">M{item['idx']}</div>
<div>
<div class="model-name">{escape(item['name'])}</div>
<div class="model-sub">Response {pos}</div>
</div>
</div>
<div class="status-badge {item['status_class']}">{item['status_label']}</div>
</div>
<div class="response-text">{escape(item['response']) or '—'}</div>
{note_html}
</div>
</div>
"""
)
if not cards:
return "<div class='empty-card'>No model responses available.</div>"
return f"""
<div class="responses-shell">
<div class="board-header">
<div>
<div class="board-title">Model Responses</div>
</div>
<div class="legend">
<span class="legend-chip"><span class="swatch" style="background:#16a34a;"></span>{correct} Correct</span>
<span class="legend-chip"><span class="swatch" style="background:#e11d48;"></span>{incorrect} Incorrect</span>
{f'<span class="legend-chip"><span class="swatch" style="background:#94a3b8;"></span>{unknown} Unlabeled</span>' if unknown else ''}
<span class="legend-chip"><span class="swatch" style="background:#4f46e5;"></span>{total} Total</span>
</div>
</div>
<div class="response-grid">{''.join(cards)}</div>
</div>
"""
def render_example(selected_label: str):
if video_examples_df.empty:
empty = "<div class='empty-card'>No sample available.</div>"
return None, empty, empty, empty
idx = VIDEO_LABELS.index(selected_label) if selected_label in VIDEO_LABELS else 0
row = video_examples_df.iloc[idx]
video_path = resolve_media_path(row.get("video_path", ""))
return video_path, render_summary_band(row), render_question_panel(row), render_response_cards(row)
with gr.Blocks(title="Benchmark Showcase", css=CUSTOM_CSS, fill_width=True) as demo:
with gr.Column(elem_id="page_shell"):
masthead = gr.HTML(value=render_masthead())
leaderboard_panel = gr.HTML(value=render_leaderboard(), elem_id="leaderboard_wrap")
with gr.Column(elem_classes=["case-shell"]):
with gr.Row(elem_classes=["case-topband"]):
case_intro = gr.HTML(value=render_case_intro())
selector = gr.Dropdown(
choices=VIDEO_LABELS,
value=VIDEO_LABELS[0],
show_label=False,
interactive=True,
container=True,
elem_id="sample_selector",
elem_classes=["case-toolbar"],
)
initial_video, initial_summary, initial_question, initial_responses = render_example(VIDEO_LABELS[0])
summary_panel = gr.HTML(value=initial_summary)
with gr.Row(equal_height=True, elem_id="hero_row"):
with gr.Column(scale=7, elem_classes=["surface-card", "video-shell"]):
video = gr.Video(
value=initial_video,
show_label=False,
interactive=False,
elem_id="main_video",
autoplay=False,
)
with gr.Column(scale=5, elem_classes=["hero-side"]):
question_panel = gr.HTML(value=initial_question)
responses_panel = gr.HTML(value=initial_responses)
def update_view(selected_label: str):
v, s, q, r = render_example(selected_label)
return v, s, q, r
selector.change(fn=update_view, inputs=selector, outputs=[video, summary_panel, question_panel, responses_panel])
if __name__ == "__main__":
demo.launch()
from __future__ import annotations
from html import escape
from pathlib import Path
import gradio as gr
import pandas as pd
BASE_DIR = Path(__file__).resolve().parent
DATA_DIR = BASE_DIR / "data"
VIDEO_CANDIDATES = [
DATA_DIR / "video_examples.csv",
BASE_DIR / "video_examples.csv",
]
LEADERBOARD_CANDIDATES = [
DATA_DIR / "eval_results.csv",
DATA_DIR / "leaderboard.csv",
DATA_DIR / "results.csv",
BASE_DIR / "eval_results.csv",
BASE_DIR / "leaderboard.csv",
BASE_DIR / "results.csv",
]
def find_existing_csv(candidates: list[Path]) -> Path | None:
for path in candidates:
if path.exists():
return path
common_names = {"eval_results.csv", "leaderboard.csv", "results.csv", "video_examples.csv"}
for path in BASE_DIR.rglob("*.csv"):
if path.name in common_names:
for candidate in candidates:
if candidate.name == path.name:
return path
return None
def safe_read_csv(path: Path | None) -> pd.DataFrame:
if path is None or not path.exists():
return pd.DataFrame()
return pd.read_csv(path)
def normalize_text(value) -> str:
if pd.isna(value):
return ""
return str(value)
def resolve_media_path(value: str) -> str | None:
value = normalize_text(value).strip()
if not value:
return None
candidate = Path(value)
if candidate.is_absolute() and candidate.exists():
return str(candidate)
for prefix in (BASE_DIR, DATA_DIR):
maybe = prefix / value
if maybe.exists():
return str(maybe)
return value
VIDEO_EXAMPLES_PATH = find_existing_csv(VIDEO_CANDIDATES)
EVAL_RESULTS_PATH = find_existing_csv(LEADERBOARD_CANDIDATES)
video_examples_df = safe_read_csv(VIDEO_EXAMPLES_PATH)
eval_results_df = safe_read_csv(EVAL_RESULTS_PATH)
CUSTOM_CSS = """
:root{
--bg:#f5f7fb;
--panel:#ffffff;
--panel-soft:rgba(255,255,255,.82);
--line:#e7edf6;
--line-strong:#d7e1ef;
--text:#0f172a;
--muted:#64748b;
--navy:#0f172a;
--slate:#1e293b;
--indigo:#4f46e5;
--violet:#7c3aed;
--cyan:#0891b2;
--teal:#0f766e;
--green:#15803d;
--rose:#e11d48;
--amber:#d97706;
--green-soft:#eefcf3;
--rose-soft:#fff1f4;
--indigo-soft:#eef2ff;
--teal-soft:#ecfeff;
--shadow:0 22px 60px rgba(15,23,42,.08);
--shadow-soft:0 10px 28px rgba(15,23,42,.05);
--radius-xl:34px;
--radius-lg:24px;
--radius-md:18px;
}
html,body,.gradio-container,gradio-app{