Spaces:
Paused
Paused
| # Build config.json at runtime from env (HF Secrets), then start server. | |
| set -e | |
| python - <<'PY' | |
| import json, os | |
| cfg = json.load(open("/app/config.example.json")) | |
| # API keys from HF Secret API_KEYS (comma-separated). Empty -> no auth. | |
| keys = [k.strip() for k in os.environ.get("API_KEYS", "").split(",") if k.strip()] | |
| cfg["api_keys"] = keys | |
| # HF Spaces serves on app_port (default 7860). | |
| cfg["port"] = int(os.environ.get("PORT", "7860")) | |
| cfg["host"] = "0.0.0.0" | |
| # Optional cookie for real Pro routing, via secret GEMINI_COOKIE. | |
| cookie = os.environ.get("GEMINI_COOKIE", "").strip() | |
| if cookie: | |
| with open("/app/cookie.txt", "w") as f: | |
| f.write(cookie) | |
| cfg["cookie_file"] = "/app/cookie.txt" | |
| # Optional outbound proxy. | |
| proxy = os.environ.get("PROXY", "").strip() | |
| if proxy: | |
| cfg["proxy"] = proxy | |
| json.dump(cfg, open("/app/config.json", "w")) | |
| print(f"config built: port={cfg['port']} auth={'on' if keys else 'off'} cookie={'yes' if cookie else 'no'}") | |
| PY | |
| exec python -m gemini_web2api --config /app/config.json | |