Tharun156 commited on
Commit
b37b470
Β·
verified Β·
1 Parent(s): aed272e

Update hf_space/app.py

Browse files
Files changed (1) hide show
  1. hf_space/app.py +60 -10
hf_space/app.py CHANGED
@@ -24,18 +24,68 @@ if str(ROOT_DIR) not in sys.path:
24
  print("[GestureLSM] sys.path:")
25
  for entry in sys.path:
26
  print(" ", entry)
27
- CKPT_DIR = BASE_DIR / "ckpt"
28
- CKPT_DIR.mkdir(parents=True, exist_ok=True)
29
 
30
  weights_repo = os.environ.get("HF_GESTURELSM_WEIGHTS_REPO", "").strip()
31
  if weights_repo:
32
- snapshot_download(
33
- repo_id=weights_repo,
34
- repo_type="dataset",
35
- local_dir=CKPT_DIR,
36
- local_dir_use_symlinks=False,
37
- allow_patterns=["*.pth", "*.bin", "*.npz", "*.npy"],
 
 
 
 
 
 
 
 
 
 
 
38
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # Ensure expected runtime directories exist so the demo can write outputs.
41
  datasets_hub_dir = ROOT_DIR / "datasets" / "hub"
@@ -46,7 +96,7 @@ smplx_dest = datasets_hub_dir / "smplx_models"
46
  smplx_dest.mkdir(parents=True, exist_ok=True)
47
 
48
  if not any(smplx_dest.iterdir()):
49
- smplx_sources = list(CKPT_DIR.glob("**/smplx_models"))
50
  if smplx_sources:
51
  smplx_source = smplx_sources[0]
52
  for item in smplx_source.iterdir():
@@ -57,7 +107,7 @@ if not any(smplx_dest.iterdir()):
57
  shutil.copy2(item, target)
58
 
59
  if not any(smplx_dest.iterdir()):
60
- archives = list(CKPT_DIR.glob("**/smplx_models.*"))
61
  for archive in archives:
62
  try:
63
  if zipfile.is_zipfile(archive):
 
24
  print("[GestureLSM] sys.path:")
25
  for entry in sys.path:
26
  print(" ", entry)
27
+ ASSET_CACHE_DIR = BASE_DIR / "asset_cache"
28
+ ASSET_CACHE_DIR.mkdir(parents=True, exist_ok=True)
29
 
30
  weights_repo = os.environ.get("HF_GESTURELSM_WEIGHTS_REPO", "").strip()
31
  if weights_repo:
32
+ downloaded_root = Path(
33
+ snapshot_download(
34
+ repo_id=weights_repo,
35
+ repo_type="dataset",
36
+ local_dir=ASSET_CACHE_DIR,
37
+ local_dir_use_symlinks=False,
38
+ allow_patterns=[
39
+ "*.pth",
40
+ "*.pt",
41
+ "*.bin",
42
+ "*.npz",
43
+ "*.npy",
44
+ "*.tar",
45
+ "*.tar.gz",
46
+ "*.zip",
47
+ ],
48
+ )
49
  )
50
+ else:
51
+ downloaded_root = ASSET_CACHE_DIR
52
+
53
+
54
+ def _sync_downloaded_assets(download_root: Path) -> None:
55
+ """Copy all downloaded asset files into the repo root."""
56
+
57
+ allowed_suffixes = {
58
+ ".pth",
59
+ ".pt",
60
+ ".bin",
61
+ ".npz",
62
+ ".npy",
63
+ ".tar",
64
+ ".gz",
65
+ ".zip",
66
+ }
67
+
68
+ copied = 0
69
+ for file_path in download_root.rglob("*"):
70
+ if not file_path.is_file():
71
+ continue
72
+ if file_path.suffix.lower() not in allowed_suffixes:
73
+ continue
74
+ relative = file_path.relative_to(download_root)
75
+ destination = ROOT_DIR / relative
76
+ destination.parent.mkdir(parents=True, exist_ok=True)
77
+ try:
78
+ shutil.copy2(file_path, destination)
79
+ copied += 1
80
+ except Exception as exc: # pragma: no cover - defensive
81
+ print(f"[GestureLSM] Failed to copy {file_path} -> {destination}: {exc}")
82
+
83
+ if copied:
84
+ print(f"[GestureLSM] Synced {copied} asset files from {download_root} to repository root")
85
+
86
+
87
+
88
+ _sync_downloaded_assets(downloaded_root)
89
 
90
  # Ensure expected runtime directories exist so the demo can write outputs.
91
  datasets_hub_dir = ROOT_DIR / "datasets" / "hub"
 
96
  smplx_dest.mkdir(parents=True, exist_ok=True)
97
 
98
  if not any(smplx_dest.iterdir()):
99
+ smplx_sources = list(ASSET_CACHE_DIR.glob("**/smplx_models"))
100
  if smplx_sources:
101
  smplx_source = smplx_sources[0]
102
  for item in smplx_source.iterdir():
 
107
  shutil.copy2(item, target)
108
 
109
  if not any(smplx_dest.iterdir()):
110
+ archives = list(ASSET_CACHE_DIR.glob("**/smplx_models.*"))
111
  for archive in archives:
112
  try:
113
  if zipfile.is_zipfile(archive):