Spaces:
Running on T4
Running on T4
github-actions[bot] commited on
Commit ·
9756876
1
Parent(s): 4bf9ad1
Automated Deploy: acb55f69ee3929c586c3ebc183e5ee1e69ca2acb
Browse files- .dockerignore +2 -0
- Dockerfile +3 -26
- Dockerfile.gvhmr +27 -0
- docs/GVHMR_SETUP.md +24 -5
- tests/test_gvhmr_motion.py +19 -0
- tools/setup_gvhmr_api_worker.py +92 -0
- tools/start_api.py +4 -6
.dockerignore
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
*
|
| 2 |
!Dockerfile
|
| 3 |
!Dockerfile.sam
|
|
|
|
| 4 |
!requirements-core.txt
|
| 5 |
!requirements-api.txt
|
| 6 |
!requirements-api-gpu.txt
|
|
@@ -31,6 +32,7 @@
|
|
| 31 |
!tools/prepare_gvhmr_assets.py
|
| 32 |
!tools/register_gvhmr_api_worker.py
|
| 33 |
!tools/check_gvhmr_runtime.py
|
|
|
|
| 34 |
!tools/start_api.py
|
| 35 |
!docs/
|
| 36 |
!docs/api-result.schema.json
|
|
|
|
| 1 |
*
|
| 2 |
!Dockerfile
|
| 3 |
!Dockerfile.sam
|
| 4 |
+
!Dockerfile.gvhmr
|
| 5 |
!requirements-core.txt
|
| 6 |
!requirements-api.txt
|
| 7 |
!requirements-api-gpu.txt
|
|
|
|
| 32 |
!tools/prepare_gvhmr_assets.py
|
| 33 |
!tools/register_gvhmr_api_worker.py
|
| 34 |
!tools/check_gvhmr_runtime.py
|
| 35 |
+
!tools/setup_gvhmr_api_worker.py
|
| 36 |
!tools/start_api.py
|
| 37 |
!docs/
|
| 38 |
!docs/api-result.schema.json
|
Dockerfile
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
ARG GVHMR_RUNTIME_BASE=sam-runtime
|
| 2 |
FROM python:3.11-slim-bookworm AS tracking-export
|
| 3 |
ENV PYTHONUNBUFFERED=1 MPLBACKEND=Agg YOLO_CONFIG_DIR=/tmp
|
| 4 |
WORKDIR /export
|
|
@@ -26,26 +25,6 @@ RUN python -m venv /opt/sam-runtime \
|
|
| 26 |
&& git -C /opt/sam-source fetch --depth=1 origin b5c765a0d89d789985e186d396315e7590887b94 \
|
| 27 |
&& git -C /opt/sam-source checkout --detach b5c765a0d89d789985e186d396315e7590887b94
|
| 28 |
|
| 29 |
-
# Inherit the completed build stage to serialize the two large CUDA installs.
|
| 30 |
-
# The final image still copies separate interpreters, never shared site-packages.
|
| 31 |
-
FROM ${GVHMR_RUNTIME_BASE} AS gvhmr-runtime
|
| 32 |
-
ENV UV_PYTHON_INSTALL_DIR=/opt/gvhmr-python UV_LINK_MODE=copy
|
| 33 |
-
RUN apt-get update && apt-get install -y --no-install-recommends git libgl1 libglib2.0-0 \
|
| 34 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 35 |
-
COPY requirements-gvhmr.txt /tmp/requirements-gvhmr.txt
|
| 36 |
-
COPY tools/check_gvhmr_runtime.py /tmp/check_gvhmr_runtime.py
|
| 37 |
-
RUN python -m pip install --no-cache-dir uv==0.9.10 \
|
| 38 |
-
&& python -m uv python install 3.10 \
|
| 39 |
-
&& python -m uv venv --python 3.10 --seed /opt/gvhmr-runtime \
|
| 40 |
-
&& /opt/gvhmr-runtime/bin/python -m pip install --no-cache-dir -r /tmp/requirements-gvhmr.txt \
|
| 41 |
-
&& git init /opt/gvhmr-source \
|
| 42 |
-
&& git -C /opt/gvhmr-source remote add origin https://github.com/zju3dv/GVHMR.git \
|
| 43 |
-
&& git -C /opt/gvhmr-source fetch --depth=1 origin ee960bb6e2ea2d381aa97f08e9b71ef320b624b1 \
|
| 44 |
-
&& git -C /opt/gvhmr-source checkout --detach ee960bb6e2ea2d381aa97f08e9b71ef320b624b1 \
|
| 45 |
-
&& PYTHONPATH=/opt/gvhmr-source /opt/gvhmr-runtime/bin/python /tmp/check_gvhmr_runtime.py
|
| 46 |
-
COPY baseball_batting /opt/gvhmr-api-check/baseball_batting
|
| 47 |
-
RUN PYTHONPATH=/opt/gvhmr-api-check:/opt/gvhmr-source /opt/gvhmr-runtime/bin/python -c \
|
| 48 |
-
"import numpy as np; from baseball_batting.gvhmr_pose_worker import run; from baseball_batting.motion_adapters import smplx_to_calculation; from smplx.joint_names import JOINT_NAMES; assert smplx_to_calculation(np.zeros((2,len(JOINT_NAMES),3)),JOINT_NAMES).shape == (2,70,3)"
|
| 49 |
|
| 50 |
FROM python:3.11-slim-bookworm
|
| 51 |
|
|
@@ -53,7 +32,7 @@ ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 MPLBACKEND=Agg \
|
|
| 53 |
PIP_NO_CACHE_DIR=1 BASEBALL_MODEL_ROOT=/opt/models BASEBALL_DATA_ROOT=/data \
|
| 54 |
NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=compute,utility \
|
| 55 |
BASEBALL_SAM_WORKER_RECORD=/data/sam-api-worker.json BASEBALL_SAM_SOURCE=/opt/sam-source \
|
| 56 |
-
BASEBALL_GVHMR_WORKER_RECORD=/data/gvhmr-api-worker.json BASEBALL_GVHMR_SOURCE=/
|
| 57 |
HF_HUB_DOWNLOAD_TIMEOUT=60
|
| 58 |
WORKDIR /app
|
| 59 |
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg libgomp1 tini git libgl1 libegl1 libglib2.0-0 \
|
|
@@ -61,6 +40,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg libgomp1
|
|
| 61 |
COPY requirements-core.txt requirements-api.txt requirements-api-gpu.txt requirements-coach.txt ./
|
| 62 |
RUN python -m pip install --only-binary=:all: -r requirements-api-gpu.txt -r requirements-coach.txt \
|
| 63 |
&& python -m pip install --no-deps rtmlib==0.0.16
|
|
|
|
| 64 |
COPY AI-coach-agent/pyproject.toml AI-coach-agent/README.md ./AI-coach-agent/
|
| 65 |
COPY AI-coach-agent/src ./AI-coach-agent/src
|
| 66 |
RUN python -m pip install --no-deps ./AI-coach-agent
|
|
@@ -70,10 +50,7 @@ COPY configs ./configs
|
|
| 70 |
COPY tools/setup_api_models.py tools/setup_full_worker.py tools/setup_sam_api_worker.py tools/register_sam_api_worker.py ./tools/
|
| 71 |
COPY tools/__init__.py ./tools/__init__.py
|
| 72 |
COPY tools/prepare_sam_assets.py tools/start_api.py ./tools/
|
| 73 |
-
COPY tools/prepare_gvhmr_assets.py tools/register_gvhmr_api_worker.py tools/check_gvhmr_runtime.py ./tools/
|
| 74 |
-
COPY --from=gvhmr-runtime /opt/gvhmr-python /opt/gvhmr-python
|
| 75 |
-
COPY --from=gvhmr-runtime /opt/gvhmr-runtime /opt/gvhmr-runtime
|
| 76 |
-
COPY --chown=1000:1000 --from=gvhmr-runtime /opt/gvhmr-source /opt/gvhmr-source
|
| 77 |
COPY --from=sam-runtime /opt/sam-runtime /opt/sam-runtime
|
| 78 |
COPY --chown=1000:1000 --from=sam-runtime /opt/sam-source /opt/sam-source
|
| 79 |
COPY docs/api-result.schema.json ./docs/api-result.schema.json
|
|
|
|
|
|
|
| 1 |
FROM python:3.11-slim-bookworm AS tracking-export
|
| 2 |
ENV PYTHONUNBUFFERED=1 MPLBACKEND=Agg YOLO_CONFIG_DIR=/tmp
|
| 3 |
WORKDIR /export
|
|
|
|
| 25 |
&& git -C /opt/sam-source fetch --depth=1 origin b5c765a0d89d789985e186d396315e7590887b94 \
|
| 26 |
&& git -C /opt/sam-source checkout --detach b5c765a0d89d789985e186d396315e7590887b94
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
FROM python:3.11-slim-bookworm
|
| 30 |
|
|
|
|
| 32 |
PIP_NO_CACHE_DIR=1 BASEBALL_MODEL_ROOT=/opt/models BASEBALL_DATA_ROOT=/data \
|
| 33 |
NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=compute,utility \
|
| 34 |
BASEBALL_SAM_WORKER_RECORD=/data/sam-api-worker.json BASEBALL_SAM_SOURCE=/opt/sam-source \
|
| 35 |
+
BASEBALL_GVHMR_WORKER_RECORD=/data/gvhmr-api-worker.json BASEBALL_GVHMR_SOURCE=/data/gvhmr-source \
|
| 36 |
HF_HUB_DOWNLOAD_TIMEOUT=60
|
| 37 |
WORKDIR /app
|
| 38 |
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg libgomp1 tini git libgl1 libegl1 libglib2.0-0 \
|
|
|
|
| 40 |
COPY requirements-core.txt requirements-api.txt requirements-api-gpu.txt requirements-coach.txt ./
|
| 41 |
RUN python -m pip install --only-binary=:all: -r requirements-api-gpu.txt -r requirements-coach.txt \
|
| 42 |
&& python -m pip install --no-deps rtmlib==0.0.16
|
| 43 |
+
COPY requirements-gvhmr.txt ./
|
| 44 |
COPY AI-coach-agent/pyproject.toml AI-coach-agent/README.md ./AI-coach-agent/
|
| 45 |
COPY AI-coach-agent/src ./AI-coach-agent/src
|
| 46 |
RUN python -m pip install --no-deps ./AI-coach-agent
|
|
|
|
| 50 |
COPY tools/setup_api_models.py tools/setup_full_worker.py tools/setup_sam_api_worker.py tools/register_sam_api_worker.py ./tools/
|
| 51 |
COPY tools/__init__.py ./tools/__init__.py
|
| 52 |
COPY tools/prepare_sam_assets.py tools/start_api.py ./tools/
|
| 53 |
+
COPY tools/prepare_gvhmr_assets.py tools/register_gvhmr_api_worker.py tools/check_gvhmr_runtime.py tools/setup_gvhmr_api_worker.py ./tools/
|
|
|
|
|
|
|
|
|
|
| 54 |
COPY --from=sam-runtime /opt/sam-runtime /opt/sam-runtime
|
| 55 |
COPY --chown=1000:1000 --from=sam-runtime /opt/sam-source /opt/sam-source
|
| 56 |
COPY docs/api-result.schema.json ./docs/api-result.schema.json
|
Dockerfile.gvhmr
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Optional image with the complete GVHMR interpreter installed at build time.
|
| 2 |
+
ARG BASE_IMAGE=baseball-engine-api:local
|
| 3 |
+
FROM python:3.11-slim-bookworm AS gvhmr-runtime
|
| 4 |
+
ENV UV_PYTHON_INSTALL_DIR=/opt/gvhmr-python UV_LINK_MODE=copy
|
| 5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends git libgl1 libglib2.0-0 \
|
| 6 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
+
COPY requirements-gvhmr.txt /tmp/requirements-gvhmr.txt
|
| 8 |
+
COPY tools/check_gvhmr_runtime.py /tmp/check_gvhmr_runtime.py
|
| 9 |
+
RUN python -m pip install --no-cache-dir uv==0.9.10 \
|
| 10 |
+
&& python -m uv python install 3.10 \
|
| 11 |
+
&& python -m uv venv --python 3.10 --seed /opt/gvhmr-runtime \
|
| 12 |
+
&& /opt/gvhmr-runtime/bin/python -m pip install --no-cache-dir -r /tmp/requirements-gvhmr.txt \
|
| 13 |
+
&& git init /opt/gvhmr-source \
|
| 14 |
+
&& git -C /opt/gvhmr-source remote add origin https://github.com/zju3dv/GVHMR.git \
|
| 15 |
+
&& git -C /opt/gvhmr-source fetch --depth=1 origin ee960bb6e2ea2d381aa97f08e9b71ef320b624b1 \
|
| 16 |
+
&& git -C /opt/gvhmr-source checkout --detach ee960bb6e2ea2d381aa97f08e9b71ef320b624b1 \
|
| 17 |
+
&& PYTHONPATH=/opt/gvhmr-source /opt/gvhmr-runtime/bin/python /tmp/check_gvhmr_runtime.py
|
| 18 |
+
COPY baseball_batting /opt/gvhmr-api-check/baseball_batting
|
| 19 |
+
RUN PYTHONPATH=/opt/gvhmr-api-check:/opt/gvhmr-source /opt/gvhmr-runtime/bin/python -c \
|
| 20 |
+
"import numpy as np; from baseball_batting.gvhmr_pose_worker import run; from baseball_batting.motion_adapters import smplx_to_calculation; from smplx.joint_names import JOINT_NAMES; assert smplx_to_calculation(np.zeros((2,len(JOINT_NAMES),3)),JOINT_NAMES).shape == (2,70,3)"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
FROM ${BASE_IMAGE}
|
| 24 |
+
COPY --from=gvhmr-runtime /opt/gvhmr-python /opt/gvhmr-python
|
| 25 |
+
COPY --from=gvhmr-runtime /opt/gvhmr-runtime /opt/gvhmr-runtime
|
| 26 |
+
COPY --chown=1000:1000 --from=gvhmr-runtime /opt/gvhmr-source /opt/gvhmr-source
|
| 27 |
+
ENV BASEBALL_GVHMR_SOURCE=/opt/gvhmr-source
|
docs/GVHMR_SETUP.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
# Enable GVHMR on the existing GPU API
|
| 2 |
|
| 3 |
-
The normal Docker image contains
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
No new public route, Gemini key or GPU purchase is needed to select GVHMR.
|
| 6 |
|
| 7 |
## Required operator-supplied file
|
|
@@ -27,10 +30,17 @@ BASEBALL_SMPLX_FILENAME=SMPLX_NEUTRAL.npz
|
|
| 27 |
|
| 28 |
Set `BASEBALL_SMPLX_REVISION` to pin a specific repository commit if desired.
|
| 29 |
Do not put the file in the public Space or GitHub repository. Restart after
|
| 30 |
-
configuring the file location.
|
|
|
|
| 31 |
records checksums and creates `/data/gvhmr-api-worker.json`. Setup failures report
|
| 32 |
safe reason codes without printing tokens or provider response bodies.
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
Until the file is supplied, capabilities reports
|
| 35 |
`gvhmr_smplx_license_asset_required`, and selecting GVHMR returns 503. SAM keeps
|
| 36 |
working. After setup, `configured: true` means files/dependencies are configured;
|
|
@@ -42,8 +52,17 @@ Source: [official GVHMR](https://github.com/zju3dv/GVHMR), pinned to
|
|
| 42 |
`ee960bb6e2ea2d381aa97f08e9b71ef320b624b1`.
|
| 43 |
|
| 44 |
The isolated Python 3.10 runtime uses upstream's Torch 2.3 / CUDA 12.1 stack and
|
| 45 |
-
official PyTorch3D wheel.
|
| 46 |
-
preflight without accessing a body model.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
Startup obtains only the three non-body checkpoints from the mirror used by
|
| 49 |
the upstream project's linked Hugging Face demo: GVHMR release, HMR2 features,
|
|
|
|
| 1 |
# Enable GVHMR on the existing GPU API
|
| 2 |
|
| 3 |
+
The normal Docker image contains SAM and an optional GVHMR bootstrap. Once the
|
| 4 |
+
licensed file location is configured, GVHMR installs into its **own** Python
|
| 5 |
+
runtime on the GPU host, in the background. This avoids the constrained Hugging
|
| 6 |
+
Face image builder running out of memory while packaging two CUDA stacks.
|
| 7 |
+
The API starts independently and SAM stays the default.
|
| 8 |
No new public route, Gemini key or GPU purchase is needed to select GVHMR.
|
| 9 |
|
| 10 |
## Required operator-supplied file
|
|
|
|
| 30 |
|
| 31 |
Set `BASEBALL_SMPLX_REVISION` to pin a specific repository commit if desired.
|
| 32 |
Do not put the file in the public Space or GitHub repository. Restart after
|
| 33 |
+
configuring the file location. First setup installs the pinned runtime and then
|
| 34 |
+
resolves/pins asset revisions,
|
| 35 |
records checksums and creates `/data/gvhmr-api-worker.json`. Setup failures report
|
| 36 |
safe reason codes without printing tokens or provider response bodies.
|
| 37 |
|
| 38 |
+
During first setup, capabilities reports `gvhmr_runtime_installing` or
|
| 39 |
+
`gvhmr_assets_installing`; selecting GVHMR returns 503 until setup completes.
|
| 40 |
+
Use persistent `/data` to retain the runtime and weights across restarts. Ephemeral
|
| 41 |
+
Space rebuilds may need to install them again. Setup logs remain private under
|
| 42 |
+
`/data/gvhmr-setup-private.log` and are not served by the API.
|
| 43 |
+
|
| 44 |
Until the file is supplied, capabilities reports
|
| 45 |
`gvhmr_smplx_license_asset_required`, and selecting GVHMR returns 503. SAM keeps
|
| 46 |
working. After setup, `configured: true` means files/dependencies are configured;
|
|
|
|
| 52 |
`ee960bb6e2ea2d381aa97f08e9b71ef320b624b1`.
|
| 53 |
|
| 54 |
The isolated Python 3.10 runtime uses upstream's Torch 2.3 / CUDA 12.1 stack and
|
| 55 |
+
official PyTorch3D wheel. CI builds the separate provider image and runs
|
| 56 |
+
inference-import/configuration preflight without accessing a body model. The host
|
| 57 |
+
installer runs the same preflight before downloading assets. SAM retains its
|
| 58 |
+
existing runtime and the GVHMR installer does not modify its packages.
|
| 59 |
+
|
| 60 |
+
For a Docker build host with sufficient memory, `Dockerfile.gvhmr` offers an image
|
| 61 |
+
with GVHMR's runtime already installed. Build the ordinary image as
|
| 62 |
+
`baseball-engine-api:local`, then build `Dockerfile.gvhmr` with that base image
|
| 63 |
+
(`BASE_IMAGE` can override the tag). Run it with the same GPU/data/secret settings.
|
| 64 |
+
Model weights and the licensed body file are still runtime assets. The standard
|
| 65 |
+
Hugging Face deployment uses background installation instead of this larger image.
|
| 66 |
|
| 67 |
Startup obtains only the three non-body checkpoints from the mirror used by
|
| 68 |
the upstream project's linked Hugging Face demo: GVHMR release, HMR2 features,
|
tests/test_gvhmr_motion.py
CHANGED
|
@@ -207,3 +207,22 @@ def test_missing_licensed_body_model_stops_setup_before_any_download(tmp_path,mo
|
|
| 207 |
assert json.loads((tmp_path/'gvhmr-setup-status.json').read_text())['reason_code']=='gvhmr_smplx_license_asset_required'
|
| 208 |
assert not (tmp_path/'gvhmr-cache').exists()
|
| 209 |
assert not (tmp_path/'gvhmr-api-worker.json').exists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
assert json.loads((tmp_path/'gvhmr-setup-status.json').read_text())['reason_code']=='gvhmr_smplx_license_asset_required'
|
| 208 |
assert not (tmp_path/'gvhmr-cache').exists()
|
| 209 |
assert not (tmp_path/'gvhmr-api-worker.json').exists()
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def test_optional_bootstrap_does_not_block_api_or_install_without_license(tmp_path,monkeypatch):
|
| 213 |
+
from tools import setup_gvhmr_api_worker as setup
|
| 214 |
+
monkeypatch.setattr('baseball_batting.gvhmr_runtime.configured_record',lambda:None)
|
| 215 |
+
monkeypatch.setenv('BASEBALL_DATA_ROOT',str(tmp_path))
|
| 216 |
+
monkeypatch.delenv('BASEBALL_GVHMR_SKIP_SETUP',raising=False)
|
| 217 |
+
monkeypatch.delenv('BASEBALL_SMPLX_MODEL_PATH',raising=False);monkeypatch.delenv('BASEBALL_SMPLX_REPO',raising=False)
|
| 218 |
+
calls=[];monkeypatch.setattr(setup.subprocess,'Popen',lambda *a,**k:calls.append((a,k)))
|
| 219 |
+
assert setup.launch_optional_setup() is False and not calls
|
| 220 |
+
assert json.loads((tmp_path/'gvhmr-setup-status.json').read_text())['reason_code']=='gvhmr_smplx_license_asset_required'
|
| 221 |
+
monkeypatch.setenv('BASEBALL_SMPLX_REPO','operator/private-licensed-copy')
|
| 222 |
+
monkeypatch.setenv('BASEBALL_API_KEY','fixture-service-secret');monkeypatch.setenv('GOOGLE_API_KEY','fixture-google-secret')
|
| 223 |
+
monkeypatch.setenv('HF_TOKEN','fixture-approved-hub-token')
|
| 224 |
+
assert setup.launch_optional_setup() is True and len(calls)==1
|
| 225 |
+
env=calls[0][1]['env']
|
| 226 |
+
assert 'BASEBALL_API_KEY' not in env and 'GOOGLE_API_KEY' not in env
|
| 227 |
+
assert env['HF_TOKEN']=='fixture-approved-hub-token'
|
| 228 |
+
assert 'HF_TOKEN' not in setup.installation_environment()
|
tools/setup_gvhmr_api_worker.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Optional provider bootstrap on the GPU host, never in the constrained HF builder.
|
| 2 |
+
|
| 3 |
+
All dependencies, Python and source are pinned. No source video or Gemini call is
|
| 4 |
+
involved. The API starts separately and advertises this model only after setup.
|
| 5 |
+
"""
|
| 6 |
+
import fcntl
|
| 7 |
+
import os
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
import shutil
|
| 10 |
+
import subprocess
|
| 11 |
+
import sys
|
| 12 |
+
from baseball_batting.motion_adapters import GVHMR_REVISION
|
| 13 |
+
from baseball_batting.storage import atomic_json
|
| 14 |
+
|
| 15 |
+
ROOT=Path(__file__).resolve().parents[1]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def installation_environment():
|
| 19 |
+
env=dict(os.environ)
|
| 20 |
+
for name in ('BASEBALL_API_KEY','GOOGLE_API_KEY','HF_TOKEN','HUGGING_FACE_HUB_TOKEN'):env.pop(name,None)
|
| 21 |
+
env.update(MAX_JOBS='1',OMP_NUM_THREADS='2',UV_CONCURRENT_DOWNLOADS='2',UV_LINK_MODE='copy',MPLBACKEND='Agg')
|
| 22 |
+
return env
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def launch_optional_setup():
|
| 26 |
+
"""Nonblocking startup. An absent licensed asset cannot delay or disable SAM."""
|
| 27 |
+
if os.environ.get('BASEBALL_GVHMR_SKIP_SETUP')=='1':return False
|
| 28 |
+
root=Path(os.environ.get('BASEBALL_DATA_ROOT','/data'));root.mkdir(parents=True,exist_ok=True)
|
| 29 |
+
from baseball_batting.gvhmr_runtime import configured_record
|
| 30 |
+
if configured_record():return False
|
| 31 |
+
body=os.environ.get('BASEBALL_SMPLX_MODEL_PATH')
|
| 32 |
+
if body and not Path(body).is_file():
|
| 33 |
+
atomic_json(root/'gvhmr-setup-status.json',{'status':'unavailable','reason_code':'gvhmr_smplx_file_missing'})
|
| 34 |
+
return False
|
| 35 |
+
if not (os.environ.get('BASEBALL_SMPLX_MODEL_PATH') or os.environ.get('BASEBALL_SMPLX_REPO')):
|
| 36 |
+
atomic_json(root/'gvhmr-setup-status.json',{'status':'unavailable','reason_code':'gvhmr_smplx_license_asset_required'})
|
| 37 |
+
return False
|
| 38 |
+
env=dict(os.environ);env.pop('BASEBALL_API_KEY',None);env.pop('GOOGLE_API_KEY',None)
|
| 39 |
+
with (root/'gvhmr-setup-private.log').open('ab') as log:
|
| 40 |
+
subprocess.Popen([sys.executable,'-m','tools.setup_gvhmr_api_worker'],env=env,
|
| 41 |
+
stdout=log,stderr=subprocess.STDOUT,start_new_session=True)
|
| 42 |
+
return True
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def main():
|
| 46 |
+
root=Path(os.environ.get('BASEBALL_DATA_ROOT','/data'));root.mkdir(parents=True,exist_ok=True)
|
| 47 |
+
status=root/'gvhmr-setup-status.json'
|
| 48 |
+
with (root/'.gvhmr-setup.lock').open('a') as lock:
|
| 49 |
+
try:fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
|
| 50 |
+
except BlockingIOError:return 0
|
| 51 |
+
def state(reason):atomic_json(status,{'status':'installing_runtime','reason_code':reason})
|
| 52 |
+
try:
|
| 53 |
+
from baseball_batting.gvhmr_runtime import configured_record
|
| 54 |
+
if configured_record():return 0
|
| 55 |
+
if not (os.environ.get('BASEBALL_SMPLX_MODEL_PATH') or os.environ.get('BASEBALL_SMPLX_REPO')):
|
| 56 |
+
atomic_json(status,{'status':'unavailable','reason_code':'gvhmr_smplx_license_asset_required'});return 1
|
| 57 |
+
env=installation_environment()
|
| 58 |
+
def run(*args,**kwargs):
|
| 59 |
+
return subprocess.run([str(a) for a in args],env=kwargs.pop('env',env),check=True,timeout=1800,**kwargs)
|
| 60 |
+
worker=Path('/opt/gvhmr-runtime/bin/python')
|
| 61 |
+
if not worker.is_file():
|
| 62 |
+
state('gvhmr_runtime_installing')
|
| 63 |
+
bootstrap=root/'.gvhmr-bootstrap';uv=bootstrap/'bin/python'
|
| 64 |
+
if not uv.is_file():run(sys.executable,'-m','venv',bootstrap)
|
| 65 |
+
run(uv,'-m','pip','install','--no-cache-dir','uv==0.9.10')
|
| 66 |
+
env['UV_PYTHON_INSTALL_DIR']=str(root/'gvhmr-python')
|
| 67 |
+
run(uv,'-m','uv','python','install','3.10')
|
| 68 |
+
runtime=root/'.runtime-gvhmr';worker=runtime/'bin/python'
|
| 69 |
+
if worker.is_file() and subprocess.run([str(worker),'-m','pip','--version'],env=env,capture_output=True).returncode:
|
| 70 |
+
shutil.rmtree(runtime)
|
| 71 |
+
if not worker.is_file():run(uv,'-m','uv','venv','--python','3.10','--seed',runtime)
|
| 72 |
+
run(worker,'-m','pip','install','--no-cache-dir','-r',ROOT/'requirements-gvhmr.txt')
|
| 73 |
+
source=Path(os.environ.get('BASEBALL_GVHMR_SOURCE',str(root/'gvhmr-source')))
|
| 74 |
+
if not (source/'.git').is_dir():
|
| 75 |
+
run('git','init',source);run('git','-C',source,'remote','add','origin','https://github.com/zju3dv/GVHMR.git')
|
| 76 |
+
run('git','-C',source,'fetch','--depth=1','origin',GVHMR_REVISION)
|
| 77 |
+
run('git','-C',source,'checkout','--detach',GVHMR_REVISION)
|
| 78 |
+
check_env={**env,'PYTHONPATH':str(source)+os.pathsep+str(ROOT)}
|
| 79 |
+
run(worker,ROOT/'tools/check_gvhmr_runtime.py',env=check_env)
|
| 80 |
+
run(worker,'-c','from baseball_batting.gvhmr_pose_worker import run',env=check_env)
|
| 81 |
+
state('gvhmr_assets_installing')
|
| 82 |
+
provider_env=dict(os.environ,BASEBALL_GVHMR_SOURCE=str(source),PYTHONPATH=str(ROOT))
|
| 83 |
+
provider_env.pop('BASEBALL_API_KEY',None);provider_env.pop('GOOGLE_API_KEY',None)
|
| 84 |
+
# This is the only step that receives normal approved HF credentials.
|
| 85 |
+
run(worker,'-m','tools.prepare_gvhmr_assets',env=provider_env)
|
| 86 |
+
return 0
|
| 87 |
+
except Exception as error:
|
| 88 |
+
atomic_json(status,{'status':'unavailable','reason_code':'gvhmr_runtime_setup_failed','error_type':type(error).__name__})
|
| 89 |
+
print('GVHMR optional runtime setup failed: '+type(error).__name__,flush=True);return 1
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
if __name__=='__main__':raise SystemExit(main())
|
tools/start_api.py
CHANGED
|
@@ -14,12 +14,10 @@ def main():
|
|
| 14 |
except subprocess.TimeoutExpired:
|
| 15 |
path=Path(os.environ.get('BASEBALL_DATA_ROOT','/data'))/'sam-setup-status.json'
|
| 16 |
path.write_text(json.dumps({'status':'unavailable','reason_code':'sam_asset_setup_timeout'}))
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
path=Path(os.environ.get('BASEBALL_DATA_ROOT','/data'))/'gvhmr-setup-status.json'
|
| 22 |
-
path.write_text(json.dumps({'status':'unavailable','reason_code':'gvhmr_asset_setup_timeout'}))
|
| 23 |
os.execv(sys.executable,[sys.executable,'-m','uvicorn','baseball_batting.api:create_app','--factory',
|
| 24 |
'--host','0.0.0.0','--port','8000','--workers','1','--timeout-graceful-shutdown','20','--no-access-log'])
|
| 25 |
|
|
|
|
| 14 |
except subprocess.TimeoutExpired:
|
| 15 |
path=Path(os.environ.get('BASEBALL_DATA_ROOT','/data'))/'sam-setup-status.json'
|
| 16 |
path.write_text(json.dumps({'status':'unavailable','reason_code':'sam_asset_setup_timeout'}))
|
| 17 |
+
from tools.setup_gvhmr_api_worker import launch_optional_setup
|
| 18 |
+
try:launch_optional_setup()
|
| 19 |
+
except OSError:
|
| 20 |
+
print('GVHMR optional setup could not start; continuing API startup',flush=True)
|
|
|
|
|
|
|
| 21 |
os.execv(sys.executable,[sys.executable,'-m','uvicorn','baseball_batting.api:create_app','--factory',
|
| 22 |
'--host','0.0.0.0','--port','8000','--workers','1','--timeout-graceful-shutdown','20','--no-access-log'])
|
| 23 |
|