File size: 1,251 Bytes
daaa6ed
 
 
 
 
 
 
914be63
 
 
daaa6ed
914be63
daaa6ed
914be63
daaa6ed
 
914be63
 
 
 
 
 
 
 
 
 
 
daaa6ed
 
 
914be63
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

HugPanel — Multi-zone workspace for HuggingFace Spaces.



Open/Closed Principle: routers are auto-discovered from the routers/ package.

Adding a new feature = adding a new file in routers/ — no changes here.

"""

from contextlib import asynccontextmanager

import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse

from routers import discover_routers
from routers.terminal import active_terminals, kill_terminal


@asynccontextmanager
async def lifespan(app: FastAPI):
    yield
    for zone_name in list(active_terminals.keys()):
        kill_terminal(zone_name)


app = FastAPI(title="HugPanel", lifespan=lifespan)

# Auto-register all routers (Open/Closed — new router files are picked up automatically)
for router in discover_routers():
    app.include_router(router)

# ── Static Files & SPA ──────────────────────────────────

app.mount("/static", StaticFiles(directory="static"), name="static")


@app.get("/")
def index():
    return FileResponse("static/index.html")


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)