yc4ny commited on
Commit
3d9c715
·
verified ·
1 Parent(s): f07b1c4

Upload b.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. b.py +92 -0
b.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # upload_all.py — preserves exact paths & case
2
+ import time
3
+ from pathlib import Path
4
+ from typing import Iterable, Set
5
+ from huggingface_hub import HfApi
6
+
7
+ REPO_ID = "yc4ny/SVAD-models" # change if needed
8
+ BASE_DIR = Path(".").resolve()
9
+
10
+ EXCLUDE_DIRS: Set[str] = {".git", ".hg", ".svn", ".idea", "__pycache__"}
11
+ EXCLUDE_FILES: Set[str] = {".DS_Store", "Thumbs.db", "desktop.ini, b.py"}
12
+
13
+ # If you want to restrict to specific top-level dirs, set like:
14
+ # LIMIT_TO_TOPLEVEL = {"avatar", "fitting", "submodules", "weights", "checkpoints", "face_warp"}
15
+ LIMIT_TO_TOPLEVEL: Set[str] | None = None
16
+
17
+ def iter_local_files(base: Path) -> Iterable[Path]:
18
+ for p in base.rglob("*"):
19
+ if p.is_dir():
20
+ if any(part in EXCLUDE_DIRS for part in p.parts):
21
+ continue
22
+ continue
23
+ if p.name in EXCLUDE_FILES:
24
+ continue
25
+ if any(part in EXCLUDE_DIRS for part in p.parts):
26
+ continue
27
+ if LIMIT_TO_TOPLEVEL is not None:
28
+ parts = p.relative_to(base).parts
29
+ if parts:
30
+ top = parts[0]
31
+ if top not in LIMIT_TO_TOPLEVEL:
32
+ continue
33
+ yield p
34
+
35
+ def main():
36
+ api = HfApi()
37
+ print(f"📦 Target repo: {REPO_ID}")
38
+ print(f"📂 Local root : {BASE_DIR}")
39
+
40
+ print("🔎 Fetching remote file list...")
41
+ remote_files = set(api.list_repo_files(repo_id=REPO_ID, repo_type="model"))
42
+ print(f" Remote has {len(remote_files)} files.")
43
+
44
+ plan: list[tuple[Path, str]] = []
45
+ for local_path in iter_local_files(BASE_DIR):
46
+ rel_posix = local_path.relative_to(BASE_DIR).as_posix()
47
+ dest = rel_posix # <-- preserve exact path & case
48
+ if dest not in remote_files:
49
+ plan.append((local_path, dest))
50
+
51
+ if not plan:
52
+ print("✅ Nothing to upload — already in sync.")
53
+ return
54
+
55
+ print(f"📝 Planned uploads: {len(plan)} files")
56
+ for lp, dp in plan[:20]:
57
+ print(f" + {lp} -> {dp}")
58
+ if len(plan) > 20:
59
+ print(" ... (truncated)")
60
+
61
+ print("\n🚀 Uploading…")
62
+ uploaded = 0
63
+ failed = 0
64
+ for idx, (local_path, dest) in enumerate(plan, 1):
65
+ tries = 0
66
+ while True:
67
+ tries += 1
68
+ try:
69
+ api.upload_file(
70
+ repo_id=REPO_ID,
71
+ repo_type="model",
72
+ path_or_fileobj=str(local_path),
73
+ path_in_repo=dest, # exact path kept
74
+ )
75
+ uploaded += 1
76
+ if uploaded % 25 == 0 or idx == len(plan):
77
+ print(f" … {uploaded}/{len(plan)} uploaded")
78
+ break
79
+ except Exception as e:
80
+ if tries < 5:
81
+ print(f"⚠️ Retry {tries}/5: {local_path} -> {dest} :: {e}")
82
+ time.sleep(2 * tries)
83
+ else:
84
+ print(f"❌ Failed: {local_path} -> {dest} :: {e}")
85
+ failed += 1
86
+ break
87
+
88
+ print(f"\n✅ Done. Uploaded {uploaded} files. {'❌ '+str(failed)+' failed.' if failed else ''}")
89
+ print("Re-run any time; it only uploads missing files.")
90
+
91
+ if __name__ == "__main__":
92
+ main()