Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from fastapi import FastAPI, Request
|
| 4 |
+
from fastapi.responses import HTMLResponse
|
| 5 |
+
from fastapi.staticfiles import StaticFiles
|
| 6 |
+
from fastapi.templating import Jinja2Templates
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import csv
|
| 9 |
+
from typing import List, Dict, Tuple
|
| 10 |
+
|
| 11 |
+
APP_DIR = Path(__file__).resolve().parent
|
| 12 |
+
CSV_PATH = APP_DIR / "leaderboard.csv"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def load_leaderboard() -> Tuple[List[str], List[Dict[str, str]]]:
|
| 16 |
+
headers: List[str] = []
|
| 17 |
+
rows: List[Dict[str, str]] = []
|
| 18 |
+
|
| 19 |
+
with CSV_PATH.open("r", encoding="utf-8") as f:
|
| 20 |
+
reader = csv.DictReader(f)
|
| 21 |
+
headers = reader.fieldnames or []
|
| 22 |
+
for row in reader:
|
| 23 |
+
rows.append(dict(row))
|
| 24 |
+
|
| 25 |
+
# Sort by Mean (Task) descending
|
| 26 |
+
def parse_score(value: str) -> float:
|
| 27 |
+
try:
|
| 28 |
+
return float(value)
|
| 29 |
+
except Exception:
|
| 30 |
+
return float("-inf")
|
| 31 |
+
|
| 32 |
+
if "Mean (Task)" in headers:
|
| 33 |
+
rows.sort(key=lambda r: parse_score(r.get("Mean (Task)", "-inf")), reverse=True)
|
| 34 |
+
|
| 35 |
+
# Add rank
|
| 36 |
+
for index, row in enumerate(rows, start=1):
|
| 37 |
+
row["Rank"] = str(index)
|
| 38 |
+
|
| 39 |
+
if "Rank" not in headers:
|
| 40 |
+
headers = ["Rank"] + headers
|
| 41 |
+
|
| 42 |
+
return headers, rows
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
app = FastAPI(title="Turkish Embedding Leaderboard")
|
| 46 |
+
|
| 47 |
+
templates = Jinja2Templates(directory=str(APP_DIR / "templates"))
|
| 48 |
+
app.mount("/static", StaticFiles(directory=str(APP_DIR / "static")), name="static")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@app.get("/", response_class=HTMLResponse)
|
| 52 |
+
async def index(request: Request) -> HTMLResponse:
|
| 53 |
+
headers, rows = load_leaderboard()
|
| 54 |
+
return templates.TemplateResponse(
|
| 55 |
+
"index.html",
|
| 56 |
+
{"request": request, "headers": headers, "rows": rows},
|
| 57 |
+
)
|