"""Streamlit app to display the NPU Arabic leaderboard.""" from __future__ import annotations import json from datetime import datetime from pathlib import Path from typing import List, Sequence import streamlit as st _DATA_PATH = Path("../leaderboard.json") _COLUMNS: Sequence[str] = ( "model_name", "avg_tps", "iwslt2017-en-ar_sacrebleu", "mlqa_ar_ar_f1", "xquad_ar_f1", "timestamp", ) def _load_rows() -> List[dict]: if not _DATA_PATH.exists(): return [] try: raw = json.loads(_DATA_PATH.read_text(encoding="utf-8")) except json.JSONDecodeError: return [] if isinstance(raw, dict): data = [raw] elif isinstance(raw, list): data = [item for item in raw if isinstance(item, dict)] else: data = [] # Filter to desired columns and sort newest-first. filtered: List[dict] = [] for row in data: compact = {key: row.get(key) for key in _COLUMNS} filtered.append(compact) def _sort_key(item: dict) -> tuple: stamp = item.get("timestamp") try: return (datetime.fromisoformat(str(stamp)),) except Exception: return (datetime.min,) filtered.sort(key=_sort_key, reverse=True) return filtered st.set_page_config(page_title="Intel NPU Arabic Leaderboard", layout="wide") st.title("IntelĀ® NPU Arabic Leaderboard") rows = _load_rows() if not rows: st.info("No evaluations uploaded yet. Trigger a run to populate the leaderboard.") else: st.write( "Latest evaluation per model. Add new results by emailing the evaluation endpoint " "or running the CLI with the Hugging Face publishing flags." ) st.dataframe(rows, column_config={col: st.column_config.Column(col) for col in _COLUMNS}) st.caption("Data auto-synced from leaderboard.json produced by the evaluation pipeline.")