atahanuz's picture
Upload app.py with huggingface_hub
3384cc0 verified
from __future__ import annotations
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from pathlib import Path
import csv
from typing import List, Dict, Tuple
APP_DIR = Path(__file__).resolve().parent
CSV_PATH = APP_DIR / "leaderboard.csv"
def load_leaderboard() -> Tuple[List[str], List[Dict[str, str]]]:
headers: List[str] = []
rows: List[Dict[str, str]] = []
with CSV_PATH.open("r", encoding="utf-8") as f:
reader = csv.DictReader(f)
headers = reader.fieldnames or []
for row in reader:
rows.append(dict(row))
def parse_score(value: str) -> float:
try:
return float(value)
except Exception:
return float("-inf")
sort_col = "Total (/60)"
if sort_col in headers:
rows.sort(key=lambda r: parse_score(r.get(sort_col, "-inf")), reverse=True)
for index, row in enumerate(rows, start=1):
row["Rank"] = str(index)
if "Rank" not in headers:
headers = ["Rank"] + headers
return headers, rows
app = FastAPI(title="AIME-TR Benchmark")
templates = Jinja2Templates(directory=str(APP_DIR / "templates"))
app.mount("/static", StaticFiles(directory=str(APP_DIR / "static")), name="static")
@app.get("/", response_class=HTMLResponse)
async def index(request: Request) -> HTMLResponse:
headers, rows = load_leaderboard()
return templates.TemplateResponse(
"index.html",
{"request": request, "headers": headers, "rows": rows},
)