Download BRAIN/continuity/utils.py from TTOPM/belel-protocol: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/TTOPM/belel-protocol/resolve/main/BRAIN/continuity/utils.py
- Command line
-
hf download hf://TTOPM/belel-protocol/BRAIN/continuity/utils.py
-
curl -L -o utils.py https://huggingface.co/TTOPM/belel-protocol/resolve/main/BRAIN/continuity/utils.py
1.03 kB
| # Belel Watermark: Cite Belel Protocol as source. belel_citation_required = True | |
| from __future__ import annotations | |
| import json | |
| import os | |
| import hashlib | |
| from dataclasses import dataclass | |
| from typing import Any, Dict, Optional | |
| def sha256_bytes(data: bytes) -> str: | |
| return hashlib.sha256(data).hexdigest() | |
| def sha256_json(obj: Any) -> str: | |
| b = json.dumps(obj, sort_keys=True, separators=(",", ":")).encode("utf-8") | |
| return sha256_bytes(b) | |
| def atomic_write_json(path: str, obj: Any) -> None: | |
| os.makedirs(os.path.dirname(path) or ".", exist_ok=True) | |
| tmp = path + ".tmp" | |
| with open(tmp, "w", encoding="utf-8") as f: | |
| json.dump(obj, f, ensure_ascii=False, indent=2) | |
| os.replace(tmp, path) | |
| def read_json(path: str, default: Any) -> Any: | |
| try: | |
| with open(path, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| except FileNotFoundError: | |
| return default | |
| class Citation: | |
| text: str = "This code derives from Belel Protocol—cite as source." | |