"""HuggingFace Space: OpenEuroLLM pretraining progress bar. Reads ``progress.json`` (current snapshot) uploaded by ``oellm-progress`` (tracker.py). Self-contained — no config.yaml needed on the Space. Locally it falls back to the repo's ``data/`` dir so the module imports for `oellm-progress-dashboard`. """ import base64 import json import mimetypes from datetime import datetime, timezone, timedelta from pathlib import Path import gradio as gr # On the Space, progress.json sits next to this file. Locally it lives under data/. _here = Path(__file__).parent DATA_DIR = _here if (_here / "progress.json").exists() else _here.parents[2] / "data" # Brand palette: dark blue, light blue, orange accent. _DARKBLUE = "#0a2a66" _LIGHTBLUE = "#38bdf8" _ORANGE = "#f97316" _GRAY_LIGHT = "#e5e7eb" _GRAY_MED = "#6b7280" _GRAY_DARK = "#1f2937" _BG = "#f9fafb" # A logo is picked up automatically if a file named logo. sits next to this # module (deployed to the Space) or in the local data/ dir. _LOGO_EXTS = (".png", ".svg", ".jpg", ".jpeg", ".webp") def _logo_data_uri() -> str | None: """Return the logo as a data URI, or None. Inlined to avoid Gradio static-file serving.""" for d in (_here, DATA_DIR): for ext in _LOGO_EXTS: p = d / f"logo{ext}" if p.exists(): mime = ( "image/svg+xml" if ext == ".svg" else (mimetypes.guess_type(p.name)[0] or "image/png") ) b64 = base64.b64encode(p.read_bytes()).decode() return f"data:{mime};base64,{b64}" return None def load_snapshot() -> dict: path = DATA_DIR / "progress.json" if not path.exists(): return {} try: return json.loads(path.read_text()) except (json.JSONDecodeError, OSError): return {} def _human_tokens(n: float) -> str: try: n = float(n) except (TypeError, ValueError): return "—" for unit, scale in (("T", 1e12), ("B", 1e9), ("M", 1e6), ("K", 1e3)): if abs(n) >= scale: return f"{n / scale:.2f}{unit}" return f"{n:.0f}" def header_html() -> str: """Branded dark-blue header band: logo (if present) · title · website link.""" snap = load_snapshot() title = snap.get("title", "OpenEuroLLM Pretraining Progress") website = snap.get("website") logo = _logo_data_uri() logo_img = ( f'logo' if logo else "" ) if website: label = website.replace("https://", "").replace("http://", "").rstrip("/") link = ( f'{label} ↗' ) else: link = "" return ( f'
' f"{logo_img}" f'

{title}

' f"{link}" f"
" ) def progress_html() -> str: snap = load_snapshot() if not snap: return f"

No progress data yet — run oellm-progress.

" pct = snap.get("progress_pct") or 0.0 pct_disp = min(max(pct, 0.0), 100.0) seen = _human_tokens(snap.get("tokens_seen")) total = _human_tokens(snap.get("tokens_total")) model = snap.get("model", "Model") updated = snap.get("updated", "") try: _cest = timezone(timedelta(hours=2)) updated_disp = datetime.fromisoformat(updated).replace(tzinfo=timezone.utc).astimezone(_cest).strftime("%Y-%m-%d %H:%M CEST") except (ValueError, TypeError): updated_disp = updated start = snap.get("start_date") try: start_disp = datetime.fromisoformat(str(start)).strftime("%d %b %Y") if start else "" except (ValueError, TypeError): start_disp = str(start) meta = " · ".join( b for b in (f"Started {start_disp}" if start_disp else "", f"Updated {updated_disp}") if b ) return ( f'
' f'

{model} Pretraining Progress

' f'

{meta}

' f'
' f'
' f'
{pct:.2f}%
' f"
" f'
' f'{seen} tokens seen' f'{total} target' f"
" + "
" ) _WANDB_URL = "https://wandb.ai/openeurollm-project/baby_9b_dense/workspace?nw=nwusertvosch" def wandb_html() -> str: return ( f'

' f"Follow the training logs live on Weights & Biases: " f'wandb' f"

" ) with gr.Blocks(title="OpenEuroLLM Pretraining Progress") as demo: header = gr.HTML(value=header_html()) bar = gr.HTML(value=progress_html()) gr.HTML(value=wandb_html()) refresh = gr.Button("🔄 Refresh") refresh.click( fn=lambda: (header_html(), progress_html()), outputs=[header, bar], ) def main(): # theme on launch() (gradio 6 moved it here from the Blocks constructor). theme = gr.themes.Soft( primary_hue="blue", font=["ui-sans-serif", "system-ui", "sans-serif"], ) demo.launch(theme=theme) if __name__ == "__main__": main()