sf895 commited on
Commit
f0a04fb
·
1 Parent(s): 990c8da

Switch archive uploads to git ssh by default

Browse files
scripts/__pycache__/pipeline01_download_video_fix_caption.cpython-312.pyc DELETED
Binary file (35.9 kB)
 
scripts/__pycache__/pipeline02_extract_dwpose_from_video.cpython-312.pyc DELETED
Binary file (13.1 kB)
 
scripts/__pycache__/pipeline03_upload_to_huggingface.cpython-312.pyc DELETED
Binary file (13.8 kB)
 
scripts/__pycache__/visualize_dwpose_npz.cpython-312.pyc DELETED
Binary file (29.6 kB)
 
scripts/pipeline03_upload_to_huggingface.py CHANGED
@@ -4,6 +4,7 @@ import argparse
4
  import json
5
  import os
6
  import shutil
 
7
  import sys
8
  import tarfile
9
  import time
@@ -27,6 +28,7 @@ DEFAULT_RAW_METADATA_DIR = REPO_ROOT / "raw_metadata"
27
  DEFAULT_ARCHIVE_DIR = REPO_ROOT / "archives"
28
  DEFAULT_PROGRESS_PATH = REPO_ROOT / "archive_upload_progress.json"
29
  DEFAULT_STATS_NPZ = REPO_ROOT / "stats.npz"
 
30
  DEFAULT_TARGET_BYTES = 14 * 1024 * 1024 * 1024
31
  COMPLETE_MARKER_NAME = ".complete"
32
 
@@ -47,6 +49,8 @@ def parse_args() -> argparse.Namespace:
47
  parser.add_argument("--target-bytes", type=int, default=DEFAULT_TARGET_BYTES)
48
  parser.add_argument("--require-target-bytes", action="store_true")
49
  parser.add_argument("--dry-run", action="store_true")
 
 
50
  parser.add_argument("--token", default=os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN"))
51
  return parser.parse_args()
52
 
@@ -134,6 +138,64 @@ def upload_archive(api: HfApi, repo_id: str, repo_type: str, archive_path: Path)
134
  )
135
 
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  def cleanup_local_assets(
138
  video_ids: Sequence[str],
139
  dataset_dir: Path,
@@ -168,11 +230,14 @@ def format_size(num_bytes: int) -> str:
168
  def main() -> None:
169
  args = parse_args()
170
  progress = load_progress(args.progress_path)
171
- api = HfApi(token=args.token)
172
  args.dataset_dir.mkdir(parents=True, exist_ok=True)
173
 
174
  try:
175
- repo_files = api.list_repo_files(repo_id=args.repo_id, repo_type=args.repo_type)
 
 
 
176
  except Exception:
177
  repo_files = []
178
 
@@ -213,7 +278,10 @@ def main() -> None:
213
  )
214
  try:
215
  create_tar_archive(archive_path, args.dataset_dir, batch_names)
216
- upload_archive(api, args.repo_id, args.repo_type, archive_path)
 
 
 
217
  except Exception as exc:
218
  update_many_video_stats(
219
  args.stats_npz,
 
4
  import json
5
  import os
6
  import shutil
7
+ import subprocess
8
  import sys
9
  import tarfile
10
  import time
 
28
  DEFAULT_ARCHIVE_DIR = REPO_ROOT / "archives"
29
  DEFAULT_PROGRESS_PATH = REPO_ROOT / "archive_upload_progress.json"
30
  DEFAULT_STATS_NPZ = REPO_ROOT / "stats.npz"
31
+ DEFAULT_GIT_CLONE_DIR = DEFAULT_ARCHIVE_DIR / ".hf_git_repo"
32
  DEFAULT_TARGET_BYTES = 14 * 1024 * 1024 * 1024
33
  COMPLETE_MARKER_NAME = ".complete"
34
 
 
49
  parser.add_argument("--target-bytes", type=int, default=DEFAULT_TARGET_BYTES)
50
  parser.add_argument("--require-target-bytes", action="store_true")
51
  parser.add_argument("--dry-run", action="store_true")
52
+ parser.add_argument("--upload-mode", choices=["git-ssh", "api"], default=os.environ.get("HF_UPLOAD_MODE", "git-ssh"))
53
+ parser.add_argument("--git-clone-dir", type=Path, default=DEFAULT_GIT_CLONE_DIR)
54
  parser.add_argument("--token", default=os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN"))
55
  return parser.parse_args()
56
 
 
138
  )
139
 
140
 
141
+ def repo_git_url(repo_id: str, repo_type: str) -> str:
142
+ prefix = ""
143
+ if repo_type == "dataset":
144
+ prefix = "datasets/"
145
+ elif repo_type == "space":
146
+ prefix = "spaces/"
147
+ return f"git@hf.co:{prefix}{repo_id}"
148
+
149
+
150
+ def run_git(command: Sequence[str], cwd: Path) -> str:
151
+ result = subprocess.run(command, cwd=str(cwd), capture_output=True, text=True)
152
+ if result.returncode != 0:
153
+ raise RuntimeError((result.stderr or result.stdout or f"git command failed: {' '.join(command)}").strip())
154
+ return (result.stdout or result.stderr or "").strip()
155
+
156
+
157
+ def ensure_git_upload_repo(clone_dir: Path, repo_id: str, repo_type: str) -> Path:
158
+ remote_url = repo_git_url(repo_id, repo_type)
159
+ clone_dir.parent.mkdir(parents=True, exist_ok=True)
160
+ if not (clone_dir / '.git').exists():
161
+ subprocess.run(["git", "clone", remote_url, str(clone_dir)], check=True, capture_output=True, text=True)
162
+ else:
163
+ configured = run_git(["git", "remote", "get-url", "origin"], clone_dir)
164
+ if configured != remote_url:
165
+ raise RuntimeError(f"Git upload clone remote mismatch: {configured} != {remote_url}")
166
+ run_git(["git", "fetch", "origin"], clone_dir)
167
+ run_git(["git", "reset", "--hard", "origin/main"], clone_dir)
168
+ run_git(["git", "lfs", "install", "--local"], clone_dir)
169
+ try:
170
+ run_git(["git", "config", "user.name"], clone_dir)
171
+ except Exception:
172
+ run_git(["git", "config", "user.name", os.environ.get("HF_GIT_USER_NAME", "sf895")], clone_dir)
173
+ try:
174
+ run_git(["git", "config", "user.email"], clone_dir)
175
+ except Exception:
176
+ run_git(["git", "config", "user.email", os.environ.get("HF_GIT_USER_EMAIL", "sf895@rutgers.edu")], clone_dir)
177
+ return clone_dir
178
+
179
+
180
+ def list_repo_files_via_git(clone_dir: Path, repo_id: str, repo_type: str) -> List[str]:
181
+ repo_dir = ensure_git_upload_repo(clone_dir, repo_id, repo_type)
182
+ return [path.name for path in repo_dir.iterdir() if path.is_file()]
183
+
184
+
185
+ def upload_archive_via_git(clone_dir: Path, repo_id: str, repo_type: str, archive_path: Path) -> None:
186
+ repo_dir = ensure_git_upload_repo(clone_dir, repo_id, repo_type)
187
+ target_path = repo_dir / archive_path.name
188
+ shutil.copy2(archive_path, target_path)
189
+ run_git(["git", "add", archive_path.name], repo_dir)
190
+ diff_result = subprocess.run(["git", "diff", "--cached", "--quiet", "--", archive_path.name], cwd=str(repo_dir))
191
+ if diff_result.returncode == 0:
192
+ return
193
+ if diff_result.returncode != 1:
194
+ raise RuntimeError(f"git diff --cached failed for {archive_path.name}")
195
+ run_git(["git", "commit", "-m", f"Add {archive_path.name}"], repo_dir)
196
+ run_git(["git", "push", "origin", "main"], repo_dir)
197
+
198
+
199
  def cleanup_local_assets(
200
  video_ids: Sequence[str],
201
  dataset_dir: Path,
 
230
  def main() -> None:
231
  args = parse_args()
232
  progress = load_progress(args.progress_path)
233
+ api = HfApi(token=args.token) if args.upload_mode == "api" else None
234
  args.dataset_dir.mkdir(parents=True, exist_ok=True)
235
 
236
  try:
237
+ if args.upload_mode == "api":
238
+ repo_files = api.list_repo_files(repo_id=args.repo_id, repo_type=args.repo_type)
239
+ else:
240
+ repo_files = list_repo_files_via_git(args.git_clone_dir, args.repo_id, args.repo_type)
241
  except Exception:
242
  repo_files = []
243
 
 
278
  )
279
  try:
280
  create_tar_archive(archive_path, args.dataset_dir, batch_names)
281
+ if args.upload_mode == "api":
282
+ upload_archive(api, args.repo_id, args.repo_type, archive_path)
283
+ else:
284
+ upload_archive_via_git(args.git_clone_dir, args.repo_id, args.repo_type, archive_path)
285
  except Exception as exc:
286
  update_many_video_stats(
287
  args.stats_npz,
utils/__pycache__/draw_dw_lib.cpython-310.pyc DELETED
Binary file (7.89 kB)
 
utils/__pycache__/draw_dw_lib.cpython-38.pyc DELETED
Binary file (7.06 kB)
 
utils/__pycache__/preprocess_video.cpython-310.pyc DELETED
Binary file (4.62 kB)
 
utils/__pycache__/preprocess_video.cpython-38.pyc DELETED
Binary file (4.67 kB)
 
utils/__pycache__/preprocess_video_improve.cpython-310.pyc DELETED
Binary file (6.4 kB)
 
utils/__pycache__/stats_npz.cpython-310.pyc DELETED
Binary file (3.36 kB)
 
utils/__pycache__/stats_npz.cpython-312.pyc DELETED
Binary file (5.44 kB)
 
utils/__pycache__/util.cpython-310.pyc DELETED
Binary file (3.86 kB)
 
utils/__pycache__/util.cpython-38.pyc DELETED
Binary file (3.89 kB)