"""MoCapAnything V2 — HuggingFace Space (ZeroGPU) thin shell. Clones the GitHub repo and runs its unified demo app (demo/app.py). That app auto- detects the ZeroGPU environment (`import spaces`), loads models on CPU at import, downloads weights + demo data from the Hub, lazy-fetches character meshes per species, and serves the interactive demo — the SAME code as the local demo, so the two never drift apart. Code: https://github.com/phongdaot/MocapAnything """ import os import sys import subprocess ROOT = os.path.dirname(os.path.abspath(__file__)) CODE = os.path.join(ROOT, "MocapAnything") # code from GitHub (once per container) if not os.path.isdir(os.path.join(CODE, "inference")): subprocess.run(["git", "clone", "--depth", "1", "https://github.com/phongdaot/MocapAnything.git", CODE], check=True) sys.path.insert(0, CODE) sys.path.insert(0, os.path.join(CODE, "demo")) os.chdir(CODE) # Run the unified demo app IN THIS __main__ module (not a separate exec dict) so the # top-level `demo` Blocks lands in __main__ — gradio's Spaces reloader/SSR looks for # `demo` there; a separate dict hides it ("Launching demo not found in __main__") and # the fallback wires events to the wrong instance → Run errors. Fix __file__ so the # app's REPO = dirname(dirname(__file__)) still resolves to the cloned repo. app_path = os.path.join(CODE, "demo", "app.py") globals()["__file__"] = app_path exec(compile(open(app_path).read(), app_path, "exec"), globals()) # rebuild: pick up asyncio-noise silence (PR #31)