File size: 1,482 Bytes
a93cf7a
e59bd9d
 
 
 
 
 
a93cf7a
 
e59bd9d
 
a93cf7a
e59bd9d
 
a93cf7a
 
 
 
 
 
 
 
 
 
 
 
e59bd9d
 
a93cf7a
 
 
 
e59bd9d
a93cf7a
 
 
e59bd9d
a93cf7a
 
 
 
 
 
e59bd9d
 
 
 
a93cf7a
 
e59bd9d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""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