File size: 2,063 Bytes
49bccfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d90fdab
 
 
 
 
 
 
 
49bccfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13eef4d
ce0d879
49bccfe
 
 
 
 
 
ce0d879
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""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


@spaces.GPU(duration=80, size="large")
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()