Spaces:
Running on Zero
Running on Zero
| 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")) | |
| 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}, | |
| ) | |