Spaces:
Paused
Paused
Download app/image/hashing.py from rishik1111/faceid: direct link, hf CLI and curl.
- Browser
- Download file 540 Bytes
-
https://huggingface.co/spaces/rishik1111/faceid/resolve/main/app/image/hashing.py
- Command line
-
hf download hf://spaces/rishik1111/faceid/app/image/hashing.py
-
curl -L -o hashing.py https://huggingface.co/spaces/rishik1111/faceid/resolve/main/app/image/hashing.py
540 Bytes
| import hashlib | |
| from pathlib import Path | |
| from PIL import Image | |
| import imagehash | |
| def sha256_file(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with open(path, "rb") as f: | |
| for chunk in iter(lambda: f.read(1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def fingerprint_image(path: Path) -> dict: | |
| image = Image.open(path) | |
| image.verify() | |
| image = Image.open(path).convert("RGB") | |
| return { | |
| "sha256": sha256_file(path), | |
| "phash": str(imagehash.phash(image)), | |
| } | |