Spaces:
Sleeping
Sleeping
| import json | |
| from pathlib import Path | |
| import gradio as gr | |
| import pandas as pd | |
| TITLE = 'QuantiPhy Leaderboard' | |
| DATA_PATH = Path("leaderboard.csv") | |
| META_PATH = Path("benchmark.json") | |
| 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.insert(0, "display_rank", x.index + 1) | |
| return x | |
| with gr.Blocks(title=TITLE) as demo: | |
| gr.Markdown(f"# {TITLE}") | |
| gr.Markdown(metric_narrative()) | |
| gr.Markdown(f"Rows: {len(df)}") | |
| 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=True) | |
| query.change(render, [query, top_k], table) | |
| top_k.change(render, [query, top_k], table) | |
| demo.launch() | |