Spaces:
Running on Zero
Running on Zero
File size: 1,961 Bytes
f1ef7e2 537dc81 f1ef7e2 537dc81 7ce1abd 537dc81 7ce1abd f1ef7e2 71c315c 6843fb9 71c315c 7ce1abd 6915adf 7ce1abd | 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import json
import os
import sys
from pathlib import Path
import spaces
ROOT = Path(__file__).resolve().parent
RUNTIME_ROOT = Path(os.environ.get("CAPSTONE_RUNTIME_ROOT", "/tmp/call-qa"))
DATA_ROOT = RUNTIME_ROOT / "data"
os.environ.setdefault("CAPSTONE_DATA_ROOT", str(DATA_ROOT))
os.environ.setdefault("CAPSTONE_EVAL_RESULTS", str(RUNTIME_ROOT / "evaluation_results"))
os.environ.setdefault("CAPSTONE_FRONTEND_PUBLIC", str(RUNTIME_ROOT / "frontend_public"))
os.environ.setdefault("CAPSTONE_ENV_FILE", str(ROOT / ".env"))
os.environ.setdefault("ENABLE_ACOUSTIC", "0")
os.environ.setdefault("START_WORKER", "1")
def _prepare_runtime() -> None:
"""Create the writable files expected by the existing pipeline modules."""
manifest = DATA_ROOT / "na_testset" / "manifest.json"
manifest.parent.mkdir(parents=True, exist_ok=True)
if not manifest.exists():
manifest.write_text(json.dumps([]), encoding="utf-8")
for path in (
RUNTIME_ROOT / "evaluation_results",
RUNTIME_ROOT / "frontend_public",
):
path.mkdir(parents=True, exist_ok=True)
_prepare_runtime()
sys.path.insert(0, str(ROOT / "backend"))
@spaces.GPU(duration=10)
def gpu_snapshot():
"""Allocate a tiny tensor to verify that ZeroGPU scheduling is available."""
import torch
probe = torch.ones(1, device="cuda")
return {
"available": bool(torch.cuda.is_available()),
"device": torch.cuda.get_device_name(0),
"probe": float(probe.item()),
}
from app.space import build_space_app, lifespan # noqa: E402
demo, server_app = build_space_app(gpu_snapshot)
if __name__ == "__main__":
port = int(os.environ.get(
"CAPSTONE_PORT",
os.environ.get("GRADIO_SERVER_PORT", os.environ.get("PORT", "7860")),
))
demo.launch(
server_name="0.0.0.0",
server_port=port,
ssr_mode=False,
_app=server_app,
app_kwargs={"lifespan": lifespan},
)
|