Upload reconstruct_model.py with huggingface_hub
Browse files- reconstruct_model.py +43 -0
reconstruct_model.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Script to reconstruct original files from split parts.
|
4 |
+
Run this after downloading the model to reconstruct large files.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import json
|
8 |
+
import os
|
9 |
+
from pathlib import Path
|
10 |
+
|
11 |
+
def reconstruct_files():
|
12 |
+
"""Reconstruct original files from parts using the manifest."""
|
13 |
+
with open("split_manifest.json", 'r') as f:
|
14 |
+
manifest = json.load(f)
|
15 |
+
|
16 |
+
for original_file, info in manifest.items():
|
17 |
+
print(f"Reconstructing {original_file}...")
|
18 |
+
|
19 |
+
output_path = Path(original_file)
|
20 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
21 |
+
|
22 |
+
with open(output_path, 'wb') as output_file:
|
23 |
+
for part_file in info["parts"]:
|
24 |
+
with open(part_file, 'rb') as part:
|
25 |
+
output_file.write(part.read())
|
26 |
+
|
27 |
+
# Verify size
|
28 |
+
if output_path.stat().st_size == info["original_size"]:
|
29 |
+
print(f" ✓ Reconstructed successfully ({output_path.stat().st_size} bytes)")
|
30 |
+
|
31 |
+
# Clean up part files
|
32 |
+
for part_file in info["parts"]:
|
33 |
+
os.remove(part_file)
|
34 |
+
print(f" Removed part: {part_file}")
|
35 |
+
else:
|
36 |
+
print(f" ✗ Size mismatch for {original_file}")
|
37 |
+
|
38 |
+
# Remove manifest after successful reconstruction
|
39 |
+
os.remove("split_manifest.json")
|
40 |
+
print("Reconstruction complete!")
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
reconstruct_files()
|