Upload /check_protec.py with huggingface_hub
Browse files- check_protec.py +25 -0
check_protec.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
def validate_hash(file_path):
|
| 3 |
+
import hashlib
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
# Load file
|
| 7 |
+
data = torch.load(file_path)
|
| 8 |
+
|
| 9 |
+
# Recalculate hash
|
| 10 |
+
metadata = data["metadata"]
|
| 11 |
+
original_hash = data["hash"]
|
| 12 |
+
recalculated_hash = hashlib.sha256(str(metadata).encode()).hexdigest()
|
| 13 |
+
|
| 14 |
+
if original_hash == recalculated_hash:
|
| 15 |
+
print("Valid metadata.")
|
| 16 |
+
return True
|
| 17 |
+
else:
|
| 18 |
+
print("Metadata tampered.")
|
| 19 |
+
return False
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"Error validating hash: {e}")
|
| 22 |
+
return False
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
validate_hash("vae_weights.pth")
|