"""
Lightweight web dashboard for the Binary Looped Hybrid trainer.
Stdlib-only HTTP server. Serves:
/ auto-refreshing HTML monitor (loss curve + live stats)
/state current state.json
/history history.jsonl (for the curve)
Run: python3 dashboard.py [port] (default 8080)
"""
import json
import os
import sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
HERE = os.path.dirname(os.path.abspath(__file__))
STATE = os.path.join(HERE, "state.json")
HISTORY = os.path.join(HERE, "history.jsonl")
PAGE = """
Binary Looped Hybrid - LIVE TRAINING
BINARY LOOPED (INTERNAL-REASONING) TRANSFORMER - MAMBA HYBRID
waiting for trainer...
LATEST GREEDY SAMPLE (prompt: 'The ')
(none yet)
"""
class Handler(BaseHTTPRequestHandler):
def log_message(self, *a): # quiet
pass
def _send(self, body, ctype):
data = body.encode("utf-8") if isinstance(body, str) else body
self.send_response(200)
self.send_header("Content-Type", ctype)
self.send_header("Content-Length", str(len(data)))
self.send_header("Cache-Control", "no-store")
self.end_headers()
self.wfile.write(data)
def do_GET(self):
if self.path == "/":
self._send(PAGE, "text/html; charset=utf-8")
elif self.path == "/state":
try:
with open(STATE, "rb") as f:
self._send(f.read(), "application/json")
except FileNotFoundError:
self._send("{}", "application/json")
elif self.path == "/history":
try:
with open(HISTORY, "rb") as f:
self._send(f.read(), "text/plain; charset=utf-8")
except FileNotFoundError:
self._send("", "text/plain; charset=utf-8")
else:
self.send_response(404)
self.end_headers()
if __name__ == "__main__":
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
ThreadingHTTPServer(("0.0.0.0", port), Handler).serve_forever()