Spaces:
Running
Running
| """Model run registry helpers.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from typing import Any | |
| def register_model_run(registry_path: Path, payload: dict[str, Any]) -> dict[str, Any]: | |
| registry_path.parent.mkdir(parents=True, exist_ok=True) | |
| if registry_path.exists(): | |
| existing = json.loads(registry_path.read_text(encoding="utf-8")) | |
| if not isinstance(existing, list): | |
| existing = [] | |
| else: | |
| existing = [] | |
| existing.append(payload) | |
| registry_path.write_text(json.dumps(existing, ensure_ascii=True, indent=2), encoding="utf-8") | |
| return {"runs": len(existing), "registry_path": str(registry_path)} | |
| def latest_run(registry_path: Path) -> dict[str, Any]: | |
| if not registry_path.exists(): | |
| return {} | |
| payload = json.loads(registry_path.read_text(encoding="utf-8")) | |
| if not payload: | |
| return {} | |
| if isinstance(payload, list): | |
| return payload[-1] | |
| return {} | |