File size: 1,040 Bytes
211ec3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
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
#!/bin/sh
# 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