-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (39 loc) · 1.57 KB
/
Copy pathapp.py
File metadata and controls
51 lines (39 loc) · 1.57 KB
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
#!/usr/bin/env python3
"""Layout-only HTMX rendering of the Recursive Benchmark Lab."""
from __future__ import annotations
from pathlib import Path
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
ROOT = Path(__file__).resolve().parent
TABS = ("benchmarks", "results", "failures", "data", "environments", "settings")
TAB_LABELS = {
"benchmarks": ("01", "Benchmarks", "done", 1),
"results": ("02", "Results", "done", 1),
"failures": ("03", "Failure map", "done", 1),
"data": ("04", "Data forge", "done", 1),
"environments": ("05", "Env lab", "active", 0),
}
app = FastAPI(title="recursive( ) htmx layout")
app.mount("/assets", StaticFiles(directory=ROOT / "static"), name="assets")
templates = Jinja2Templates(directory=str(ROOT / "templates"))
def context(request: Request, tab: str) -> dict:
if tab not in TABS:
tab = "benchmarks"
return {
"request": request,
"tab": tab,
"tabs": TABS,
"tab_labels": TAB_LABELS,
"hx": request.headers.get("HX-Request") == "true",
}
@app.get("/", response_class=HTMLResponse)
@app.get("/{tab}", response_class=HTMLResponse)
def page(request: Request, tab: str = "benchmarks") -> HTMLResponse:
ctx = context(request, tab)
template = "workspace.html" if ctx["hx"] else "layout.html"
return templates.TemplateResponse(template, ctx)
if __name__ == "__main__":
import uvicorn
uvicorn.run("app:app", host="127.0.0.1", port=8766, reload=True)