Download qa/store.py from modventures/floor-visualizer-gpu: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/modventures/floor-visualizer-gpu/resolve/main/qa/store.py
- Command line
-
hf download hf://spaces/modventures/floor-visualizer-gpu/qa/store.py
-
curl -L -o store.py https://huggingface.co/spaces/modventures/floor-visualizer-gpu/resolve/main/qa/store.py
1.33 kB
| """QA run persistence helpers: read/write run JSON, SSE formatting, utilities.""" | |
| import json | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| from config.paths import QA_RUN_DIR | |
| from errors import bad_request, not_found | |
| def qa_utc_now() -> datetime: | |
| return datetime.now(timezone.utc) | |
| def qa_iso_now() -> str: | |
| return qa_utc_now().isoformat().replace("+00:00", "Z") | |
| def qa_run_root(run_id: str) -> Path: | |
| if Path(run_id).name != run_id or not run_id: | |
| bad_request("Invalid QA run id.") | |
| return QA_RUN_DIR / run_id | |
| def qa_run_file(run_id: str) -> Path: | |
| return qa_run_root(run_id) / "run.json" | |
| def read_qa_run(run_id: str) -> dict: | |
| path = qa_run_file(run_id) | |
| if not path.exists(): | |
| not_found("QA run not found.") | |
| return json.loads(path.read_text()) | |
| def write_qa_run(run: dict): | |
| run["updatedAt"] = qa_iso_now() | |
| root = qa_run_root(run["id"]) | |
| root.mkdir(parents=True, exist_ok=True) | |
| qa_run_file(run["id"]).write_text(json.dumps(run, indent=2)) | |
| def qa_sse_event(event_name: str, payload: dict) -> str: | |
| data = json.dumps(payload, separators=(",", ":")) | |
| return f"event: {event_name}\ndata: {data}\n\n" | |
| def qa_int(value, default: int = 0) -> int: | |
| try: | |
| return int(value) | |
| except (TypeError, ValueError): | |
| return default | |