jkorstad commited on
Commit
81c97ab
·
verified ·
1 Parent(s): f104497

Update setup_blender.sh

Browse files
Files changed (1) hide show
  1. setup_blender.sh +78 -39
setup_blender.sh CHANGED
@@ -1,6 +1,4 @@
1
  #!/bin/bash
2
-
3
- # Exit immediately if a command exits with a non-zero status.
4
  set -e
5
 
6
  # --- Configuration ---
@@ -11,31 +9,43 @@ BLENDER_TARBALL="blender-${BLENDER_VERSION}-linux-x64.tar.xz"
11
  BLENDER_URL="https://download.blender.org/release/Blender${BLENDER_MAJOR_MINOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz"
12
  INSTALL_DIR="/opt/blender-${BLENDER_VERSION}-linux-x64"
13
  BLENDER_PY_EXEC="${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}/python/bin/${BLENDER_PYTHON_VERSION}"
14
- UNIRIG_REQS_FILE="/home/user/app/unirig_requirements.txt" # Adjust path if different
 
 
 
 
 
15
  TORCH_VERSION="2.3.1"
16
  TORCHVISION_VERSION="0.18.1"
17
- TORCH_CUDA_SUFFIX="cu121"
18
- TORCH_INDEX_URL="https://download.pytorch.org/whl/${TORCH_CUDA_SUFFIX}"
19
- # Define the PyG wheel index URL (use the one compatible with torch 2.3.1, even if named 2.3.0)
20
- PYG_WHEEL_INDEX="https://data.pyg.org/whl/torch-2.3.0+cu121.html" # Compatible with 2.3.1
 
 
21
 
22
  # --- Set Environment Variables for Build ---
23
- # Define CUDA Home (adjust if the path is different in the Space environment)
24
- export CUDA_HOME=/usr/local/cuda
25
- echo "Setting CUDA_HOME=${CUDA_HOME}"
26
- # Add CUDA bin directory to PATH to help find nvcc
27
  export PATH="${CUDA_HOME}/bin:${PATH}"
28
- echo "Prepending CUDA bin to PATH: ${PATH}"
29
-
 
30
 
31
  # --- Download and Extract Blender ---
32
  echo "Downloading Blender ${BLENDER_VERSION}..."
33
- wget -nv -O /tmp/${BLENDER_TARBALL} ${BLENDER_URL}
34
- echo "Download complete."
 
 
 
35
 
36
  echo "Extracting Blender to ${INSTALL_DIR}..."
37
- mkdir -p /opt
38
- tar -xJf /tmp/${BLENDER_TARBALL} -C /opt
 
 
 
 
39
  echo "Extraction complete."
40
 
41
  # --- Create Blender Symlink ---
@@ -44,44 +54,73 @@ ln -sf ${INSTALL_DIR}/blender /usr/local/bin/blender
44
  echo "Symlink created."
45
 
46
  # --- Install Dependencies into Blender's Python ---
47
- echo "Installing dependencies into Blender's Python (${BLENDER_PYTHON_VERSION})..."
48
-
49
- # Check if Blender Python executable exists
50
  if [ ! -f "${BLENDER_PY_EXEC}" ]; then
51
  echo "ERROR: Blender Python executable not found at ${BLENDER_PY_EXEC}!"
52
  exit 1
53
  fi
54
-
55
- # Check if the requirements file exists
56
- if [ ! -f "${UNIRIG_REQS_FILE}" ]; then
57
- echo "ERROR: Requirements file not found at ${UNIRIG_REQS_FILE}!"
58
  exit 1
59
  fi
60
 
61
- # Upgrade pip, setuptools, and wheel within Blender's Python environment
62
- # Run this with the modified PATH and CUDA_HOME set
63
  echo "Upgrading pip for Blender Python..."
64
- "${BLENDER_PY_EXEC}" -m pip install --upgrade pip setuptools wheel
65
 
66
- # Install PyTorch and Torchvision first using the specified index URL
67
- echo "Installing PyTorch ${TORCH_VERSION} and Torchvision ${TORCHVISION_VERSION} (CUDA: ${TORCH_CUDA_SUFFIX})..."
68
- # Ensure CUDA_HOME and updated PATH are available for this step too
69
  "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir \
70
  torch==${TORCH_VERSION} \
71
  torchvision==${TORCHVISION_VERSION} \
72
  --index-url ${TORCH_INDEX_URL}
73
 
74
- # Install remaining dependencies from the requirements file
75
- # Use the -f flag to point pip to the PyG wheel index page
76
- # CUDA_HOME and updated PATH should be inherited by this pip process
77
- echo "Installing remaining packages from ${UNIRIG_REQS_FILE} with PyG wheel index..."
78
- "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir -r "${UNIRIG_REQS_FILE}" -f ${PYG_WHEEL_INDEX}
79
 
80
- echo "Dependency installation complete."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  # --- Cleanup ---
83
- echo "Cleaning up downloaded tarball..."
84
- rm /tmp/${BLENDER_TARBALL}
85
  echo "Cleanup complete."
86
-
87
  echo "Blender setup finished successfully."
 
 
1
  #!/bin/bash
 
 
2
  set -e
3
 
4
  # --- Configuration ---
 
9
  BLENDER_URL="https://download.blender.org/release/Blender${BLENDER_MAJOR_MINOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz"
10
  INSTALL_DIR="/opt/blender-${BLENDER_VERSION}-linux-x64"
11
  BLENDER_PY_EXEC="${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}/python/bin/${BLENDER_PYTHON_VERSION}"
12
+
13
+ # Path to your Gradio Space's unirig_requirements.txt (copy of UniRig's official)
14
+ UNIRIG_REQS_FILE_IN_SPACE="/home/user/app/unirig_requirements.txt"
15
+ # Path to the cloned UniRig repository in the Space
16
+ UNIRIG_REPO_CLONE_DIR="/home/user/app/UniRig" # Standard path
17
+
18
  TORCH_VERSION="2.3.1"
19
  TORCHVISION_VERSION="0.18.1"
20
+ NUMPY_VERSION="1.26.4"
21
+ TARGET_CUDA_VERSION_SHORT="cu121" # Verify ZeroGPU environment.
22
+
23
+ TORCH_INDEX_URL="https://download.pytorch.org/whl/${TARGET_CUDA_VERSION_SHORT}"
24
+ PYG_FIND_LINKS_URL="https://data.pyg.org/whl/torch-${TORCH_VERSION}+${TARGET_CUDA_VERSION_SHORT}.html"
25
+ SPCONV_PACKAGE="spconv-${TARGET_CUDA_VERSION_SHORT}"
26
 
27
  # --- Set Environment Variables for Build ---
28
+ export CUDA_HOME=${CUDA_HOME:-/usr/local/cuda}
 
 
 
29
  export PATH="${CUDA_HOME}/bin:${PATH}"
30
+ export MAX_JOBS=4
31
+ echo "Using CUDA_HOME=${CUDA_HOME}"
32
+ echo "Updated PATH: ${PATH}"
33
 
34
  # --- Download and Extract Blender ---
35
  echo "Downloading Blender ${BLENDER_VERSION}..."
36
+ if [ ! -f "/tmp/${BLENDER_TARBALL}" ]; then
37
+ wget -nv -O /tmp/${BLENDER_TARBALL} ${BLENDER_URL}
38
+ else
39
+ echo "Blender tarball /tmp/${BLENDER_TARBALL} already downloaded."
40
+ fi
41
 
42
  echo "Extracting Blender to ${INSTALL_DIR}..."
43
+ if [ ! -d "${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}" ]; then
44
+ mkdir -p /opt
45
+ tar -xJf /tmp/${BLENDER_TARBALL} -C /opt
46
+ else
47
+ echo "Blender already extracted to ${INSTALL_DIR}."
48
+ fi
49
  echo "Extraction complete."
50
 
51
  # --- Create Blender Symlink ---
 
54
  echo "Symlink created."
55
 
56
  # --- Install Dependencies into Blender's Python ---
57
+ echo "Installing dependencies into Blender's Python (${BLENDER_PY_EXEC})..."
 
 
58
  if [ ! -f "${BLENDER_PY_EXEC}" ]; then
59
  echo "ERROR: Blender Python executable not found at ${BLENDER_PY_EXEC}!"
60
  exit 1
61
  fi
62
+ if [ ! -f "${UNIRIG_REQS_FILE_IN_SPACE}" ]; then
63
+ echo "ERROR: UniRig requirements file not found at ${UNIRIG_REQS_FILE_IN_SPACE}!"
 
 
64
  exit 1
65
  fi
66
 
 
 
67
  echo "Upgrading pip for Blender Python..."
68
+ "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir --upgrade pip setuptools wheel
69
 
70
+ echo "1. Installing PyTorch ${TORCH_VERSION} and Torchvision ${TORCHVISION_VERSION}..."
 
 
71
  "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir \
72
  torch==${TORCH_VERSION} \
73
  torchvision==${TORCHVISION_VERSION} \
74
  --index-url ${TORCH_INDEX_URL}
75
 
76
+ echo "2. Installing dependencies from ${UNIRIG_REQS_FILE_IN_SPACE} (includes bpy, flash_attn)..."
77
+ "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir -r "${UNIRIG_REQS_FILE_IN_SPACE}"
 
 
 
78
 
79
+ echo "3. Installing ${SPCONV_PACKAGE}..."
80
+ "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir ${SPCONV_PACKAGE}
81
+
82
+ echo "4. Installing torch-scatter and torch-cluster..."
83
+ "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir \
84
+ torch-scatter \
85
+ torch-cluster \
86
+ -f "${PYG_FIND_LINKS_URL}"
87
+
88
+ echo "5. Installing numpy==${NUMPY_VERSION}..."
89
+ "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir numpy==${NUMPY_VERSION}
90
+
91
+ echo "Dependency installation for Blender's Python complete."
92
+
93
+ # --- FIX: Ensure UniRig/src is treated as a package ---
94
+ UNIRIG_SRC_DIR="${UNIRIG_REPO_CLONE_DIR}/src"
95
+ INIT_PY_PATH="${UNIRIG_SRC_DIR}/__init__.py"
96
+ if [ -d "${UNIRIG_SRC_DIR}" ]; then
97
+ if [ ! -f "${INIT_PY_PATH}" ]; then
98
+ echo "Creating missing __init__.py in ${UNIRIG_SRC_DIR} to make it a package..."
99
+ touch "${INIT_PY_PATH}"
100
+ echo "__init__.py created."
101
+ else
102
+ echo "${INIT_PY_PATH} already exists."
103
+ fi
104
+ else
105
+ echo "WARNING: UniRig src directory not found at ${UNIRIG_SRC_DIR}. Cannot create __init__.py."
106
+ fi
107
+ # --- END FIX ---
108
+
109
+ # (Optional) VRM Addon installation
110
+ VRM_ADDON_REL_PATH="blender/add-on-vrm-v2.20.77_modified.zip"
111
+ ABSOLUTE_ADDON_PATH="${UNIRIG_REPO_CLONE_DIR}/${VRM_ADDON_REL_PATH}"
112
+ if [ -f "${ABSOLUTE_ADDON_PATH}" ]; then
113
+ echo "Installing optional VRM addon for Blender..."
114
+ (cd "${UNIRIG_REPO_CLONE_DIR}" && \
115
+ "${BLENDER_PY_EXEC}" -c "import bpy, os; bpy.ops.preferences.addon_install(overwrite=True, filepath=os.path.abspath('${VRM_ADDON_REL_PATH}')); bpy.ops.preferences.addon_enable(module='io_scene_vrm'); print('VRM Addon installed and enabled.')")
116
+ echo "VRM addon installation attempted."
117
+ else
118
+ echo "VRM addon zip not found at ${ABSOLUTE_ADDON_PATH}, skipping addon installation."
119
+ fi
120
 
121
  # --- Cleanup ---
122
+ echo "Cleaning up downloaded Blender tarball..."
123
+ rm -f /tmp/${BLENDER_TARBALL}
124
  echo "Cleanup complete."
 
125
  echo "Blender setup finished successfully."
126
+