RunyiY commited on
Commit
36ed084
·
verified ·
1 Parent(s): d431f60

Upload structured3d/download.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. structured3d/download.py +138 -0
structured3d/download.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Download script for structured3d dataset chunks from Hugging Face
4
+ """
5
+
6
+ import os
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ try:
11
+ from huggingface_hub import hf_hub_download, list_repo_files
12
+ except ImportError:
13
+ print("Error: huggingface_hub not installed")
14
+ print("Install with: pip install huggingface_hub")
15
+ sys.exit(1)
16
+
17
+ DATASET_NAME = "structured3d"
18
+ DEFAULT_REPO_ID = f"your-username/{DATASET_NAME}-dataset"
19
+
20
+ def download_chunks(repo_id, token=None):
21
+ """Download structured3d chunks from Hugging Face."""
22
+
23
+ try:
24
+ # List files in the repository
25
+ files = list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)
26
+
27
+ # Filter chunk files
28
+ chunk_files = [f for f in files if f.startswith(f"{DATASET_NAME}/{DATASET_NAME}_part_")]
29
+
30
+ if not chunk_files:
31
+ print(f"Error: No chunks found in {repo_id}")
32
+ print(f"Expected files like {DATASET_NAME}/{DATASET_NAME}_part_000")
33
+ return False
34
+
35
+ print(f"Found {len(chunk_files)} chunks to download")
36
+ print(f"Warning: This will download ~307GB of data. Ensure you have enough disk space!")
37
+
38
+ response = input("Continue with download? (y/N): ")
39
+ if response.lower() != 'y':
40
+ print("Download cancelled.")
41
+ return False
42
+
43
+ # Create chunks directory
44
+ chunks_dir = Path("chunks")
45
+ chunks_dir.mkdir(exist_ok=True)
46
+
47
+ # Download each chunk
48
+ for i, file_path in enumerate(sorted(chunk_files)):
49
+ chunk_name = Path(file_path).name
50
+ local_path = chunks_dir / chunk_name
51
+
52
+ print(f"Downloading {chunk_name} ({i+1}/{len(chunk_files)})...")
53
+
54
+ try:
55
+ hf_hub_download(
56
+ repo_id=repo_id,
57
+ repo_type="dataset",
58
+ filename=file_path,
59
+ local_dir=".",
60
+ token=token
61
+ )
62
+
63
+ # Move to chunks directory
64
+ downloaded_path = Path(file_path)
65
+ if downloaded_path.exists():
66
+ downloaded_path.rename(local_path)
67
+
68
+ except Exception as e:
69
+ print(f" ✗ Error downloading {chunk_name}: {e}")
70
+ continue
71
+
72
+ # Download helper scripts
73
+ helper_files = [f for f in files if f.startswith(f"{DATASET_NAME}/") and f.endswith(('.sh', '.py'))]
74
+ for file_path in helper_files:
75
+ script_name = Path(file_path).name
76
+ if script_name != "download.py": # Don't overwrite ourselves
77
+ print(f"Downloading {script_name}...")
78
+ try:
79
+ hf_hub_download(
80
+ repo_id=repo_id,
81
+ repo_type="dataset",
82
+ filename=file_path,
83
+ local_dir=".",
84
+ token=token
85
+ )
86
+
87
+ # Move to current directory and make executable
88
+ downloaded_path = Path(file_path)
89
+ if downloaded_path.exists():
90
+ downloaded_path.rename(script_name)
91
+ if script_name.endswith('.sh'):
92
+ os.chmod(script_name, 0o755)
93
+
94
+ except Exception as e:
95
+ print(f" ✗ Error downloading {script_name}: {e}")
96
+
97
+ # Clean up empty directories
98
+ dataset_dir = Path(DATASET_NAME)
99
+ if dataset_dir.exists() and not any(dataset_dir.iterdir()):
100
+ dataset_dir.rmdir()
101
+
102
+ print(f"\n✓ Download complete!")
103
+ print(f"Downloaded {len(chunk_files)} chunks to chunks/ directory")
104
+ print("\nNext steps:")
105
+ print("1. Run ./merge.sh to reassemble the original file")
106
+ print("2. Run ./extract.sh to extract contents")
107
+ print("\nWarning: Extraction will require additional ~307GB of disk space!")
108
+
109
+ return True
110
+
111
+ except Exception as e:
112
+ print(f"Error accessing repository {repo_id}: {e}")
113
+ return False
114
+
115
+ def main():
116
+ import argparse
117
+
118
+ parser = argparse.ArgumentParser(description=f"Download {DATASET_NAME} chunks from Hugging Face")
119
+ parser.add_argument("repo_id", nargs="?", default=DEFAULT_REPO_ID, help="Hugging Face repository ID")
120
+ parser.add_argument("--token", help="Hugging Face token (or set HF_TOKEN env var)")
121
+
122
+ args = parser.parse_args()
123
+
124
+ # Get token (optional for public repos)
125
+ token = args.token or os.getenv("HF_TOKEN")
126
+
127
+ print(f"Downloading from: {args.repo_id}")
128
+
129
+ success = download_chunks(
130
+ repo_id=args.repo_id,
131
+ token=token
132
+ )
133
+
134
+ if not success:
135
+ sys.exit(1)
136
+
137
+ if __name__ == "__main__":
138
+ main()