Spaces:
Sleeping
Sleeping
| 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") | |
| 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, | |
| ) | |
| def healthz(): | |
| return { | |
| "ok": REPORT.exists(), | |
| "site_root": str(SITE_ROOT), | |
| "report": str(REPORT), | |
| } | |
| def report(): | |
| if REPORT.exists(): | |
| return FileResponse(REPORT) | |
| return root() | |
| if SITE_ROOT.exists(): | |
| app.mount("/", StaticFiles(directory=SITE_ROOT, html=True), name="site") | |