Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,59 +1,53 @@
|
|
| 1 |
-
# main.py — ASGI entrypoint for BubbleGuard Web (HF-ready, with GDrive fetch)
|
| 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 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
print("[BubbleGuard] Uvicorn failed to start:", file=sys.stderr)
|
| 55 |
-
traceback.print_exc()
|
| 56 |
-
raise SystemExit(1)
|
| 57 |
-
|
| 58 |
-
if __name__ == "__main__":
|
| 59 |
-
main()
|
|
|
|
| 1 |
+
# main.py — ASGI entrypoint for BubbleGuard Web (HF-ready, with GDrive fetch)
|
| 2 |
+
# Author: Amir
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import traceback
|
| 7 |
+
|
| 8 |
+
def _truthy(val: str) -> bool:
|
| 9 |
+
return str(val).strip().lower() in {"1", "true", "yes", "on"}
|
| 10 |
+
|
| 11 |
+
def main() -> None:
|
| 12 |
+
host = os.getenv("HOST", "0.0.0.0")
|
| 13 |
+
port = int(os.getenv("PORT", "8000"))
|
| 14 |
+
debug = _truthy(os.getenv("DEBUG", "0"))
|
| 15 |
+
|
| 16 |
+
print(f"[BubbleGuard] Starting server on {host}:{port}")
|
| 17 |
+
folder_id = os.getenv("GDRIVE_FOLDER_ID", "").strip()
|
| 18 |
+
if folder_id:
|
| 19 |
+
print(f"[BubbleGuard] Using Google Drive folder: {folder_id}")
|
| 20 |
+
else:
|
| 21 |
+
print("[BubbleGuard] No GDRIVE_FOLDER_ID set (will fail to load assets).")
|
| 22 |
+
|
| 23 |
+
# Ensure assets before importing the app
|
| 24 |
+
try:
|
| 25 |
+
from download_assets import ensure_all_assets
|
| 26 |
+
ensure_all_assets()
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print("[BubbleGuard] ERROR while preparing assets:", file=sys.stderr)
|
| 29 |
+
traceback.print_exc()
|
| 30 |
+
raise SystemExit(1)
|
| 31 |
+
|
| 32 |
+
# Start Uvicorn after assets are ready
|
| 33 |
+
try:
|
| 34 |
+
import uvicorn
|
| 35 |
+
uvicorn.run(
|
| 36 |
+
"app_server:app",
|
| 37 |
+
host=host,
|
| 38 |
+
port=port,
|
| 39 |
+
reload=False,
|
| 40 |
+
workers=1,
|
| 41 |
+
log_level="debug" if debug else "info",
|
| 42 |
+
proxy_headers=True,
|
| 43 |
+
forwarded_allow_ips="*",
|
| 44 |
+
timeout_keep_alive=10,
|
| 45 |
+
access_log=True,
|
| 46 |
+
)
|
| 47 |
+
except Exception:
|
| 48 |
+
print("[BubbleGuard] Uvicorn failed to start:", file=sys.stderr)
|
| 49 |
+
traceback.print_exc()
|
| 50 |
+
raise SystemExit(1)
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|