Deepfake Authenticator commited on
Commit ·
e0772b8
1
Parent(s): e669b79
fix: serve frontend-vanilla on HF Space, add static file catch-all
Browse files- backend/main.py +14 -0
backend/main.py
CHANGED
|
@@ -114,6 +114,7 @@ authenticator = None
|
|
| 114 |
async def startup_event():
|
| 115 |
global authenticator
|
| 116 |
logger.info("Initializing DeepfakeAuthenticator...")
|
|
|
|
| 117 |
authenticator = DeepfakeAuthenticator()
|
| 118 |
logger.info(
|
| 119 |
f"DeepfakeAuthenticator ready — model: "
|
|
@@ -343,6 +344,8 @@ if _react_dist.exists():
|
|
| 343 |
return {"detail": "Not found"}
|
| 344 |
|
| 345 |
elif _vanilla_dir.exists():
|
|
|
|
|
|
|
| 346 |
@app.get("/script.js")
|
| 347 |
async def serve_script():
|
| 348 |
return FileResponse(
|
|
@@ -365,6 +368,17 @@ elif _vanilla_dir.exists():
|
|
| 365 |
headers={"Cache-Control": "no-store, no-cache, must-revalidate"},
|
| 366 |
)
|
| 367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
|
| 369 |
if __name__ == "__main__":
|
| 370 |
import uvicorn
|
|
|
|
| 114 |
async def startup_event():
|
| 115 |
global authenticator
|
| 116 |
logger.info("Initializing DeepfakeAuthenticator...")
|
| 117 |
+
logger.info(f"Frontend path: {_vanilla_dir} (exists={_vanilla_dir.exists()})")
|
| 118 |
authenticator = DeepfakeAuthenticator()
|
| 119 |
logger.info(
|
| 120 |
f"DeepfakeAuthenticator ready — model: "
|
|
|
|
| 344 |
return {"detail": "Not found"}
|
| 345 |
|
| 346 |
elif _vanilla_dir.exists():
|
| 347 |
+
from fastapi.staticfiles import StaticFiles as SF
|
| 348 |
+
|
| 349 |
@app.get("/script.js")
|
| 350 |
async def serve_script():
|
| 351 |
return FileResponse(
|
|
|
|
| 368 |
headers={"Cache-Control": "no-store, no-cache, must-revalidate"},
|
| 369 |
)
|
| 370 |
|
| 371 |
+
# Serve any other static file from frontend-vanilla/
|
| 372 |
+
@app.get("/{filename:path}")
|
| 373 |
+
async def serve_static(filename: str):
|
| 374 |
+
file_path = _vanilla_dir / filename
|
| 375 |
+
if file_path.exists() and file_path.is_file():
|
| 376 |
+
return FileResponse(str(file_path))
|
| 377 |
+
return FileResponse(
|
| 378 |
+
str(_vanilla_dir / "index.html"),
|
| 379 |
+
headers={"Cache-Control": "no-store, no-cache, must-revalidate"},
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
|
| 383 |
if __name__ == "__main__":
|
| 384 |
import uvicorn
|