Spaces:
Sleeping
Sleeping
Download src/decision_model/artifacts.py from xstard/decision-model: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/xstard/decision-model/resolve/main/src/decision_model/artifacts.py
- Command line
-
hf download hf://spaces/xstard/decision-model/src/decision_model/artifacts.py
-
curl -L -o artifacts.py https://huggingface.co/spaces/xstard/decision-model/resolve/main/src/decision_model/artifacts.py
1.24 kB
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import re | |
| def sha256(path): | |
| digest = hashlib.sha256() | |
| with Path(path).open("rb") as stream: | |
| for chunk in iter(lambda: stream.read(1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def verify_bundle(path): | |
| path = Path(path) | |
| manifest = json.loads((path / "manifest.json").read_text(encoding="utf-8")) | |
| required = {"head.safetensors", "calibration.json", "metrics.json"} | |
| if manifest.get('encoder_delta'): | |
| required.add('encoder_delta.safetensors') | |
| if manifest.get("format_version") != 1 or set(manifest.get("files", {})) != required: | |
| raise ValueError("Неповний manifest артефактів.") | |
| if not re.fullmatch(r"[a-f0-9]{40}", manifest.get("encoder_revision", "")): | |
| raise ValueError("Не зафіксовано ревізію encoder.") | |
| if not isinstance(manifest.get("hidden_size"), int) or manifest["hidden_size"] <= 0: | |
| raise ValueError("Некоректний hidden_size.") | |
| for name, digest in manifest["files"].items(): | |
| if sha256(path / name) != digest: | |
| raise ValueError(f"SHA256 не збігається: {name}") | |
| return manifest | |