"""FastAPI control surface for the agent (served on localhost). Start / pause / resume / stop the worker, set nothing else here (config is env), and watch progress + the server-side queue. The container exposes this on a localhost port; stopping the worker frees the GPU. """ from fastapi import FastAPI from fastapi.responses import HTMLResponse, JSONResponse from .config import Config from .worker import Worker cfg = Config.from_env() worker = Worker(cfg) app = FastAPI(title="FabledCurator GPU agent") @app.get("/", response_class=HTMLResponse) def index() -> str: return _PAGE @app.post("/start") def start(): worker.start() return JSONResponse(worker.status()) @app.post("/pause") def pause(): worker.pause() return JSONResponse(worker.status()) @app.post("/resume") def resume(): worker.resume() return JSONResponse(worker.status()) @app.post("/stop") def stop(): worker.stop() return JSONResponse(worker.status()) @app.get("/status") def status(): s = worker.status() s["fc_url"] = cfg.fc_url s["configured"] = bool(cfg.token) try: s["queue"] = worker.client.queue_status() except Exception: s["queue"] = None return JSONResponse(s) _PAGE = """
FC: — · token —
idle
state
0
processed
0
errors
—
current image