Spaces:
Sleeping
Sleeping
File size: 1,177 Bytes
2a07a4a | 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 | from __future__ import annotations
import os
from pathlib import Path
from fastapi import FastAPI
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse
from fastapi.staticfiles import StaticFiles
SITE_ROOT = Path(os.environ.get("SITE_ROOT", "/data")).resolve()
REPORT = SITE_ROOT / "analysis" / "report.html"
app = FastAPI(title="Birch HTML Benchmark")
@app.get("/")
def root():
if REPORT.exists():
return RedirectResponse("/analysis/report.html", status_code=302)
return HTMLResponse(
"<!doctype html><title>Birch HTML Benchmark</title>"
"<h1>Birch HTML Benchmark</h1>"
f"<p>Report not found at <code>{REPORT}</code>. "
"Check that the bucket is mounted at <code>/data</code>.</p>",
status_code=503,
)
@app.get("/healthz")
def healthz():
return {
"ok": REPORT.exists(),
"site_root": str(SITE_ROOT),
"report": str(REPORT),
}
@app.get("/analysis/report.html")
def report():
if REPORT.exists():
return FileResponse(REPORT)
return root()
if SITE_ROOT.exists():
app.mount("/", StaticFiles(directory=SITE_ROOT, html=True), name="site")
|