Download utils/hash_utils.py from Bosch09/Eureka2: direct link, hf CLI and curl.
- Browser
- Download file 837 Bytes
-
https://huggingface.co/spaces/Bosch09/Eureka2/resolve/main/utils/hash_utils.py
- Command line
-
hf download hf://spaces/Bosch09/Eureka2/utils/hash_utils.py
-
curl -L -o hash_utils.py https://huggingface.co/spaces/Bosch09/Eureka2/resolve/main/utils/hash_utils.py
837 Bytes
| # ============================================================ | |
| # utils/hash_utils.py | |
| # ============================================================ | |
| import json | |
| import hashlib | |
| def generate_sha256_hash(payload): | |
| """ | |
| Creates a SHA256 hash for audit evidence. | |
| """ | |
| text = json.dumps( | |
| payload, | |
| sort_keys=True, | |
| default=str | |
| ) | |
| return hashlib.sha256( | |
| text.encode("utf-8") | |
| ).hexdigest() | |
| def generate_dataframe_hash(df): | |
| """ | |
| Creates a stable hash for a dataframe. | |
| Useful for proving result integrity. | |
| """ | |
| if df is None or len(df) == 0: | |
| return generate_sha256_hash({"data": "empty"}) | |
| csv_text = df.to_csv( | |
| index=False | |
| ) | |
| return hashlib.sha256( | |
| csv_text.encode("utf-8") | |
| ).hexdigest() |