Spaces:
Running
Running
| # main.py — ASGI entrypoint for BubbleGuard Web (HF-ready, with GDrive fetch) | |
| import os, sys, traceback | |
| def _truthy(val: str) -> bool: | |
| return str(val).strip().lower() in {"1", "true", "yes", "on"} | |
| def main() -> None: | |
| host = os.getenv("HOST", "0.0.0.0") | |
| port = int(os.getenv("PORT", "8000")) | |
| debug = _truthy(os.getenv("DEBUG", "0")) | |
| print(f"[BubbleGuard] Starting server on {host}:{port}") | |
| folder_id = os.getenv("GDRIVE_FOLDER_ID", "").strip() | |
| print(f"[BubbleGuard] GDRIVE_FOLDER_ID: {folder_id or '(not set!)'}") | |
| try: | |
| from download_assets import ensure_all_assets | |
| ensure_all_assets() | |
| except Exception: | |
| print("[BubbleGuard] ERROR while preparing assets:", file=sys.stderr) | |
| traceback.print_exc() | |
| raise SystemExit(1) | |
| try: | |
| import uvicorn | |
| uvicorn.run( | |
| "app_server:app", | |
| host=host, | |
| port=port, | |
| reload=False, | |
| workers=1, | |
| log_level="debug" if debug else "info", | |
| proxy_headers=True, | |
| forwarded_allow_ips="*", | |
| timeout_keep_alive=10, | |
| access_log=True, | |
| ) | |
| except Exception: | |
| print("[BubbleGuard] Uvicorn failed to start:", file=sys.stderr) | |
| traceback.print_exc() | |
| raise SystemExit(1) | |
| if __name__ == "__main__": | |
| main() | |