Spaces:
Running on Zero
Running on Zero
Deploy ControlPlane.ai
Browse filesFiles changed (2)
23 unmodified lines242526272829304 unmodified lines35363738394028 unmodified lines6970717273747523 unmodified linessys.path.insert(0, str(ROOT))for _k, _v in {"PORT": "7860","HF_HUB_DISABLE_TELEMETRY": "1","TOKENIZERS_PARALLELISM": "false","ANONYMIZED_TELEMETRY": "False",4 unmodified linesfor _k in ("HF_HUB_OFFLINE", "TRANSFORMERS_OFFLINE"): # models are not pre-baked hereos.environ.pop(_k, None)from controlplane.app import warm # noqa: E402warm.start()28 unmodified linesif __name__ == "__main__":import uvicornport = int(os.environ["PORT"])if not os.getenv("BACKEND_SECRET", "").strip():print("[start] WARNING: BACKEND_SECRET is not set - every API call will be rejected (503).", flush=True)print(f"[start] serving API on :{port} (allowed origins: {os.getenv('ALLOWED_ORIGINS', '') or '-'})", flush=True)23 unmodified lines2425262728294 unmodified lines343536373839404142434428 unmodified lines7374757677787923 unmodified linessys.path.insert(0, str(ROOT))for _k, _v in {"HF_HUB_DISABLE_TELEMETRY": "1","TOKENIZERS_PARALLELISM": "false","ANONYMIZED_TELEMETRY": "False",4 unmodified linesfor _k in ("HF_HUB_OFFLINE", "TRANSFORMERS_OFFLINE"): # models are not pre-baked hereos.environ.pop(_k, None)# Hugging Face proxies a Gradio Space on GRADIO_SERVER_PORT (7860). The ZeroGPU# runtime ALSO exports PORT=7861 and keeps that port for itself, so PORT must be# ignored here (binding it fails with "address already in use").PORT = int(os.getenv("GRADIO_SERVER_PORT") or 7860)from controlplane.app import warm # noqa: E402warm.start()28 unmodified linesif __name__ == "__main__":import uvicornport = PORTif not os.getenv("BACKEND_SECRET", "").strip():print("[start] WARNING: BACKEND_SECRET is not set - every API call will be rejected (503).", flush=True)print(f"[start] serving API on :{port} (allowed origins: {os.getenv('ALLOWED_ORIGINS', '') or '-'})", flush=True)
235 unmodified lines236237238235 unmodified lines# the Space has no build step: models must be allowed to download at bootassert os.environ.get("CP_DETOXIFY_ALLOW_DOWNLOAD") == "1"assert "HF_HUB_OFFLINE" not in os.environ235 unmodified lines236237238239240241242243244245246247248249250251252253254255256235 unmodified lines# the Space has no build step: models must be allowed to download at bootassert os.environ.get("CP_DETOXIFY_ALLOW_DOWNLOAD") == "1"assert "HF_HUB_OFFLINE" not in os.environdef test_space_entry_ignores_runtime_port_variable(store, monkeypatch):"""ZeroGPU sets PORT=7861 (and holds that port); a Gradio Space is proxied on7860 (GRADIO_SERVER_PORT). app.py must never bind to PORT."""import importlibimport sysmonkeypatch.setenv("BACKEND_SECRET", "s3cret")monkeypatch.setenv("CP_SKIP_WARMUP", "1")monkeypatch.setenv("PORT", "7861")monkeypatch.delenv("GRADIO_SERVER_PORT", raising=False)sys.modules.pop("app", None)mod = importlib.import_module("app")assert mod.PORT == 7860monkeypatch.setenv("GRADIO_SERVER_PORT", "7865")sys.modules.pop("app", None)assert importlib.import_module("app").PORT == 7865
app.py+6-2
controlplane/tests/test_api.py+18