"""LPU AI Accelerator — FastAPI control plane (delivered V7.1 shape).""" from __future__ import annotations import sys from pathlib import Path from typing import Optional from fastapi import FastAPI from fastapi.responses import FileResponse from lpu.version import __version__ as LPU_VERSION _created = False def _find_dashboard() -> Optional[Path]: candidates = [Path(__file__).resolve().parent.parent / "frontend" / "dashboard.html"] meipass = getattr(sys, "_MEIPASS", None) if meipass: m = Path(meipass) candidates += [m / "frontend" / "dashboard.html", m.parent / "frontend" / "dashboard.html"] for cand in candidates: if cand.exists(): return cand return None def create_app(config: dict | None = None) -> FastAPI: global _created cfg = config or {} app = FastAPI(title="LPU AI Accelerator V7", version=LPU_VERSION) @app.on_event("startup") async def _startup() -> None: pass @app.get("/") async def dashboard(): dash = _find_dashboard() if dash is None: return {"error": "dashboard.html missing"} return FileResponse(dash, media_type="text/html") @app.get("/api/status") async def status(): return { "runtime_version": LPU_VERSION, "accelerator_status": "running" if cfg.get("accelerator", {}).get("autostart") else "stopped", } return app