Claquasse commited on
Commit
8f55977
·
verified ·
1 Parent(s): bb73c72

Pose node: HF->mirror detector fetch with size guard (China-friendlier), keeps openmmlab fallback

Browse files
anima_control_tools.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6392aa9312eb2e7ed63a9fd2073e420b1d6564ffc7d263cbffb3336419b4f600
3
- size 27610
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bcd28519425a96b85ab5a52bf99014519812c81fca6c863fc72d7391c5dabcb1
3
+ size 28067
comfyui/ComfyUI-anima-pose-control/detect.py CHANGED
@@ -35,8 +35,47 @@ def _rtmlib_ckpt_dir():
35
  return os.path.join(os.path.expanduser(base), "rtmlib", "hub", "checkpoints")
36
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def _ensure_models():
39
- """Pre-seed rtmlib's checkpoint cache from the HF model repo so it never hits
40
  download.openmmlab.com. Best-effort: on failure, rtmlib falls back to its own download."""
41
  ckpt_dir = _rtmlib_ckpt_dir()
42
  # A leftover <base>.zip means an earlier download failed mid-way (openmmlab returned a
@@ -54,17 +93,12 @@ def _ensure_models():
54
  missing = [m for m in _MODELS if not os.path.exists(os.path.join(ckpt_dir, m))]
55
  if not missing:
56
  return
57
- try:
58
- import shutil
59
- from huggingface_hub import hf_hub_download
60
- os.makedirs(ckpt_dir, exist_ok=True)
61
- for name in missing:
62
- src = hf_hub_download(repo_id=_HF_REPO, filename="detector/" + name)
63
- shutil.copyfile(src, os.path.join(ckpt_dir, name))
64
- except Exception as e:
65
- print("[AnimaPoseControl] could not fetch the pose detector from Hugging Face (%r). "
66
- "rtmlib will try download.openmmlab.com instead; if that fails with "
67
- "'getaddrinfo failed', see the model card for the offline install." % (e,))
68
 
69
 
70
  def _default_estimator(resolution):
 
35
  return os.path.join(os.path.expanduser(base), "rtmlib", "hub", "checkpoints")
36
 
37
 
38
+ # huggingface.co is often blocked/throttled in mainland China; hf-mirror.com mirrors it and is
39
+ # reachable there. We try the Hub first (honoring HF_ENDPOINT if the user set one), then the mirror.
40
+ _MIRROR = "https://hf-mirror.com"
41
+
42
+
43
+ def _looks_real(path):
44
+ # a real .onnx is tens-to-hundreds of MB; an HTML error page or partial is tiny.
45
+ return os.path.exists(path) and os.path.getsize(path) > 1_000_000
46
+
47
+
48
+ def _fetch(name, dst):
49
+ """Download detector/<name> to dst, trying the HF Hub then the China-friendly mirror.
50
+ Returns True only on a plausibly-complete file (guards against caching an error page)."""
51
+ import shutil
52
+ try:
53
+ from huggingface_hub import hf_hub_download
54
+ src = hf_hub_download(repo_id=_HF_REPO, filename="detector/" + name)
55
+ shutil.copyfile(src, dst)
56
+ if _looks_real(dst):
57
+ return True
58
+ except Exception:
59
+ pass
60
+ try:
61
+ import urllib.request
62
+ url = "%s/%s/resolve/main/detector/%s" % (_MIRROR, _HF_REPO, name)
63
+ with urllib.request.urlopen(url, timeout=120) as r, open(dst, "wb") as f:
64
+ shutil.copyfileobj(r, f)
65
+ if _looks_real(dst):
66
+ return True
67
+ except Exception:
68
+ pass
69
+ if os.path.exists(dst) and not _looks_real(dst):
70
+ try:
71
+ os.remove(dst) # never leave a partial/HTML stub behind
72
+ except OSError:
73
+ pass
74
+ return False
75
+
76
+
77
  def _ensure_models():
78
+ """Pre-seed rtmlib's checkpoint cache from the HF model repo (or its mirror) so it never hits
79
  download.openmmlab.com. Best-effort: on failure, rtmlib falls back to its own download."""
80
  ckpt_dir = _rtmlib_ckpt_dir()
81
  # A leftover <base>.zip means an earlier download failed mid-way (openmmlab returned a
 
93
  missing = [m for m in _MODELS if not os.path.exists(os.path.join(ckpt_dir, m))]
94
  if not missing:
95
  return
96
+ os.makedirs(ckpt_dir, exist_ok=True)
97
+ for name in missing:
98
+ if not _fetch(name, os.path.join(ckpt_dir, name)):
99
+ print("[AnimaPoseControl] could not fetch %s from Hugging Face or its mirror. "
100
+ "rtmlib will try download.openmmlab.com instead; if that fails, see the model "
101
+ "card for the offline install." % name)
 
 
 
 
 
102
 
103
 
104
  def _default_estimator(resolution):