Spaces:
Running on Zero
Running on Zero
Download app/models/weights.py from suplo6669/sharpify-ai-inference: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/suplo6669/sharpify-ai-inference/resolve/main/app/models/weights.py
- Command line
-
hf download hf://spaces/suplo6669/sharpify-ai-inference/app/models/weights.py
-
curl -L -o weights.py https://huggingface.co/spaces/suplo6669/sharpify-ai-inference/resolve/main/app/models/weights.py
1.08 kB
| """Identity and integrity checks for the official x4 model checkpoint.""" | |
| from __future__ import annotations | |
| import hashlib | |
| from pathlib import Path | |
| MODEL_FILENAME = "RealESRGAN_x4plus.pth" | |
| MODEL_BYTES = 67_040_989 | |
| MODEL_SHA256 = "4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1" | |
| CHUNK_SIZE = 1024 * 1024 | |
| def sha256_file(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as source: | |
| for chunk in iter(lambda: source.read(CHUNK_SIZE), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def verify_checkpoint(path: Path) -> str: | |
| """Require the known official checkpoint bytes before loading model state.""" | |
| size = path.stat().st_size | |
| if size != MODEL_BYTES: | |
| raise RuntimeError( | |
| f"Expected a {MODEL_BYTES:,}-byte {MODEL_FILENAME} checkpoint, got {size:,}." | |
| ) | |
| digest = sha256_file(path) | |
| if digest != MODEL_SHA256: | |
| raise RuntimeError( | |
| f"The checkpoint SHA-256 does not match the official {MODEL_FILENAME} file." | |
| ) | |
| return digest | |