"""Shared look-and-feel: page config, CSS injection, header, GPU status, job badges.""" from __future__ import annotations import streamlit as st # Palette matching the hand-drawn diagrams. COLORS = { "data": "#27ae60", "proc": "#2c6fbb", "store": "#16a085", "model": "#d48806", "rl": "#e67e22", "loss": "#c0392b", "eval": "#8e44ad", "ckpt": "#888888", } _CSS = """ """ _BADGE = {"running": ("b-run", "running"), "finished": ("b-ok", "finished"), "failed": ("b-fail", "failed"), "stopped": ("b-idle", "stopped"), "none": ("b-idle", "idle")} def setup_page(title: str, icon: str = "🧠") -> None: st.set_page_config(page_title=f"{title} · Train LLM From Scratch", page_icon=icon, layout="wide") st.markdown(_CSS, unsafe_allow_html=True) def hero(title: str, subtitle: str) -> None: st.markdown(f'

{title}

{subtitle}

', unsafe_allow_html=True) def status_badge(status: str) -> str: cls, label = _BADGE.get(status, ("b-idle", status)) return f'{label}' def gpu_status(): """Return a list of (idx, name, used_mb, total_mb, util) via nvidia-smi, or [].""" import shutil import subprocess if not shutil.which("nvidia-smi"): return [] try: out = subprocess.check_output( ["nvidia-smi", "--query-gpu=index,name,memory.used,memory.total,utilization.gpu", "--format=csv,noheader,nounits"], text=True, timeout=5) except Exception: # noqa: BLE001 return [] rows = [] for line in out.strip().splitlines(): i, name, used, total, util = [x.strip() for x in line.split(",")] rows.append((int(i), name, int(used), int(total), int(util))) return rows