Spaces:
Running on Zero
Running on Zero
Download app.py from bear-ty/BeyondRetarget: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/spaces/bear-ty/BeyondRetarget/resolve/main/app.py
- Command line
-
hf download hf://spaces/bear-ty/BeyondRetarget/app.py
-
curl -L -o app.py https://huggingface.co/spaces/bear-ty/BeyondRetarget/resolve/main/app.py
2.06 kB
| """Minimal public ZeroGPU shell for the private BeyondRetarget runtime.""" | |
| from __future__ import annotations | |
| import os | |
| import sys | |
| from pathlib import Path | |
| import gradio as gr | |
| import spaces | |
| from huggingface_hub import snapshot_download | |
| PRIVATE_REPO_ID = os.environ.get( | |
| "PRIVATE_REPO_ID", | |
| "bear-ty/BeyondRetarget-runtime-private", | |
| ).strip() | |
| PRIVATE_REPO_TOKEN = os.environ.get("PRIVATE_REPO_TOKEN", "").strip() | |
| if not PRIVATE_REPO_TOKEN: | |
| raise RuntimeError( | |
| "PRIVATE_REPO_TOKEN is not configured. Add it as a Hugging Face Space secret." | |
| ) | |
| RUNTIME_ROOT = Path("/tmp/beyondretarget_runtime") | |
| snapshot_download( | |
| repo_id=PRIVATE_REPO_ID, | |
| repo_type="model", | |
| token=PRIVATE_REPO_TOKEN, | |
| local_dir=str(RUNTIME_ROOT), | |
| ) | |
| RUNTIME_ROOT = RUNTIME_ROOT.resolve() | |
| required_files = [ | |
| RUNTIME_ROOT / "runtime_app.py", | |
| RUNTIME_ROOT / "inference_pipeline.py", | |
| RUNTIME_ROOT / "weights" / "checkpoints" / "rgb2robo_multirobot_enhance_clean_20260821_175328.pth", | |
| RUNTIME_ROOT / "weights" / "hmr2" / "epoch=10-step=25000.ckpt", | |
| RUNTIME_ROOT / "weights" / "yolo" / "yolov8x.pt", | |
| ] | |
| missing_files = [str(path.relative_to(RUNTIME_ROOT)) for path in required_files if not path.is_file()] | |
| if missing_files: | |
| raise RuntimeError(f"Private runtime is incomplete; missing: {', '.join(missing_files)}") | |
| os.environ.setdefault("RGB2ROBO_CHECKPOINT_DIR", str(RUNTIME_ROOT / "weights")) | |
| os.environ.setdefault("BEYONDRETARGET_OUTPUT_DIR", "/tmp/beyondretarget_outputs") | |
| os.environ.setdefault("MUJOCO_GL", "egl") | |
| os.environ.setdefault("PYOPENGL_PLATFORM", "egl") | |
| os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "TRUE") | |
| sys.path.insert(0, str(RUNTIME_ROOT)) | |
| from runtime_app import create_demo, run_gpu_stage # noqa: E402 | |
| def zero_gpu_inference(video_path: str, progress=gr.Progress()) -> dict: | |
| return run_gpu_stage(video_path, progress=progress) | |
| demo = create_demo(zero_gpu_inference) | |
| demo.queue(default_concurrency_limit=1, max_size=3) | |
| if __name__ == "__main__": | |
| demo.launch() | |