Spaces:
Runtime error
Runtime error
Download scripts/init_db.py from Corin1998/GrowthOps_OS: direct link, hf CLI and curl.
- Browser
- Download file 946 Bytes
-
https://huggingface.co/spaces/Corin1998/GrowthOps_OS/resolve/main/scripts/init_db.py
- Command line
-
hf download hf://spaces/Corin1998/GrowthOps_OS/scripts/init_db.py
-
curl -L -o init_db.py https://huggingface.co/spaces/Corin1998/GrowthOps_OS/resolve/main/scripts/init_db.py
946 Bytes
| import os, time, requests | |
| # Wait a bit for uvicorn to become available | |
| port = int(os.getenv("PORT", "7860")) | |
| base = f"http://127.0.0.1:{port}" | |
| for _ in range(60): | |
| try: | |
| r = requests.get(f"{base}/healthz", timeout=1) | |
| if r.status_code == 200: | |
| break | |
| except Exception: | |
| pass | |
| time.sleep(1) | |
| # Ensure DB created by hitting a simple endpoint (lazy create_all on import) | |
| try: | |
| requests.get(f"{base}/healthz", timeout=3) | |
| except Exception as e: | |
| print("init_db: healthz failed:", e) | |
| # Create admin if envs are present | |
| email = os.getenv("ADMIN_EMAIL") | |
| password = os.getenv("ADMIN_PASSWORD") | |
| if email and password: | |
| try: | |
| resp = requests.post(f"{base}/auth/bootstrap_admin", json={ | |
| "email": email, "password": password | |
| }, timeout=5) | |
| print("bootstrap_admin:", resp.status_code, resp.text[:500]) | |
| except Exception as e: | |
| print("bootstrap_admin failed:", e) | |