Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -175,15 +175,14 @@ def run_unirig_command(python_script_path: str, script_args: List[str], step_nam
|
|
| 175 |
|
| 176 |
# Environment variables might still be useful if the script imports other non-blender libs
|
| 177 |
process_env = os.environ.copy()
|
| 178 |
-
# Ensure UniRig source is findable if scripts use relative imports from repo root
|
| 179 |
-
# or if they import modules from UniRig/src
|
| 180 |
unirig_src_dir = os.path.join(UNIRIG_REPO_DIR, "src")
|
|
|
|
|
|
|
| 181 |
pythonpath_parts = [
|
| 182 |
-
# Blender's site-packages should be found automatically when run via Blender exec
|
| 183 |
unirig_src_dir,
|
| 184 |
-
UNIRIG_REPO_DIR
|
|
|
|
| 185 |
]
|
| 186 |
-
# Add existing PYTHONPATH if any
|
| 187 |
existing_pythonpath = process_env.get('PYTHONPATH', '')
|
| 188 |
if existing_pythonpath:
|
| 189 |
pythonpath_parts.append(existing_pythonpath)
|
|
@@ -202,7 +201,7 @@ def run_unirig_command(python_script_path: str, script_args: List[str], step_nam
|
|
| 202 |
# cwd=UNIRIG_REPO_DIR ensures script runs relative to repo root.
|
| 203 |
result = subprocess.run(
|
| 204 |
cmd,
|
| 205 |
-
cwd=UNIRIG_REPO_DIR,
|
| 206 |
capture_output=True,
|
| 207 |
text=True,
|
| 208 |
check=True, # Raises CalledProcessError on non-zero exit codes
|
|
@@ -225,9 +224,10 @@ def run_unirig_command(python_script_path: str, script_args: List[str], step_nam
|
|
| 225 |
print(f"--- {step_name} STDERR ---:\n{e.stderr}")
|
| 226 |
error_summary = e.stderr.strip().splitlines()
|
| 227 |
last_lines = "\n".join(error_summary[-5:]) if error_summary else "No stderr output."
|
| 228 |
-
# Check specifically for
|
| 229 |
-
|
| 230 |
-
|
|
|
|
| 231 |
raise gr.Error(f"Error in UniRig '{step_name}': Blender failed to provide 'bpy' module internally.")
|
| 232 |
elif "ImportError: Failed to load PyTorch C extensions" in e.stderr:
|
| 233 |
raise gr.Error(f"Error in UniRig '{step_name}': Script failed to load PyTorch extensions even within Blender. Check installation.")
|
|
@@ -281,13 +281,7 @@ def rig_glb_mesh_multistep(input_glb_file_obj):
|
|
| 281 |
abs_final_rigged_glb_path = os.path.join(processing_temp_dir, f"{base_name}_rigged_final.glb")
|
| 282 |
|
| 283 |
# --- Define Absolute Paths to UniRig PYTHON Scripts ---
|
| 284 |
-
# ***
|
| 285 |
-
# *** This might need adjustment based on the actual content of the .sh files. ***
|
| 286 |
-
# Use run.py as the main entry point, passing task-specific configs/args
|
| 287 |
-
# This requires inspecting run.py and the shell scripts to know the correct args/configs.
|
| 288 |
-
# For now, let's assume a structure like: python run.py --config <config_file> --input ... --output ...
|
| 289 |
-
|
| 290 |
-
# Example: Assuming run.py takes task name and args
|
| 291 |
run_script_path = os.path.join(UNIRIG_REPO_DIR, "run.py") # Main script?
|
| 292 |
|
| 293 |
# --- Execute UniRig Steps ---
|
|
@@ -295,17 +289,14 @@ def rig_glb_mesh_multistep(input_glb_file_obj):
|
|
| 295 |
# Step 1: Skeleton Prediction
|
| 296 |
print("\nStarting Step 1: Predicting Skeleton...")
|
| 297 |
# Arguments for the run.py script for skeleton task
|
| 298 |
-
# ** These are GUESSES
|
| 299 |
skeleton_args = [
|
| 300 |
-
#
|
| 301 |
-
# e.g., "--task", "generate_skeleton",
|
| 302 |
"--input", abs_input_glb_path,
|
| 303 |
"--output", abs_skeleton_output_path
|
| 304 |
-
# Add other relevant args like model path if needed
|
| 305 |
]
|
| 306 |
-
if not os.path.exists(run_script_path):
|
| 307 |
raise gr.Error(f"UniRig main script not found at: {run_script_path}")
|
| 308 |
-
# Execute run.py via Blender
|
| 309 |
run_unirig_command(run_script_path, skeleton_args, "Skeleton Prediction")
|
| 310 |
if not os.path.exists(abs_skeleton_output_path):
|
| 311 |
raise gr.Error("Skeleton prediction failed. Output file not created. Check logs.")
|
|
@@ -314,11 +305,11 @@ def rig_glb_mesh_multistep(input_glb_file_obj):
|
|
| 314 |
# Step 2: Skinning Weight Prediction
|
| 315 |
print("\nStarting Step 2: Predicting Skinning Weights...")
|
| 316 |
# Arguments for the run.py script for skinning task
|
| 317 |
-
# ** GUESSES - VERIFY
|
| 318 |
skin_args = [
|
| 319 |
-
#
|
| 320 |
-
"--input", abs_skeleton_output_path,
|
| 321 |
-
"--source", abs_input_glb_path,
|
| 322 |
"--output", abs_skin_output_path
|
| 323 |
]
|
| 324 |
run_unirig_command(run_script_path, skin_args, "Skinning Prediction")
|
|
@@ -329,11 +320,9 @@ def rig_glb_mesh_multistep(input_glb_file_obj):
|
|
| 329 |
# Step 3: Merge Skeleton/Skin with Original Mesh
|
| 330 |
print("\nStarting Step 3: Merging Results...")
|
| 331 |
# Arguments for the run.py script for merging task
|
| 332 |
-
# ** GUESSES - VERIFY
|
| 333 |
-
# Alternatively, merge might use a different script like src/data/merge_fbx.py?
|
| 334 |
-
# Let's assume run.py handles it for now.
|
| 335 |
merge_args = [
|
| 336 |
-
#
|
| 337 |
"--source", abs_skin_output_path,
|
| 338 |
"--target", abs_input_glb_path,
|
| 339 |
"--output", abs_final_rigged_glb_path
|
|
|
|
| 175 |
|
| 176 |
# Environment variables might still be useful if the script imports other non-blender libs
|
| 177 |
process_env = os.environ.copy()
|
|
|
|
|
|
|
| 178 |
unirig_src_dir = os.path.join(UNIRIG_REPO_DIR, "src")
|
| 179 |
+
|
| 180 |
+
# Set PYTHONPATH: Include UniRig source dir, UniRig base dir, and '.' for CWD.
|
| 181 |
pythonpath_parts = [
|
|
|
|
| 182 |
unirig_src_dir,
|
| 183 |
+
UNIRIG_REPO_DIR,
|
| 184 |
+
'.' # Add current working directory explicitly
|
| 185 |
]
|
|
|
|
| 186 |
existing_pythonpath = process_env.get('PYTHONPATH', '')
|
| 187 |
if existing_pythonpath:
|
| 188 |
pythonpath_parts.append(existing_pythonpath)
|
|
|
|
| 201 |
# cwd=UNIRIG_REPO_DIR ensures script runs relative to repo root.
|
| 202 |
result = subprocess.run(
|
| 203 |
cmd,
|
| 204 |
+
cwd=UNIRIG_REPO_DIR, # CWD is set to UniRig repo root
|
| 205 |
capture_output=True,
|
| 206 |
text=True,
|
| 207 |
check=True, # Raises CalledProcessError on non-zero exit codes
|
|
|
|
| 224 |
print(f"--- {step_name} STDERR ---:\n{e.stderr}")
|
| 225 |
error_summary = e.stderr.strip().splitlines()
|
| 226 |
last_lines = "\n".join(error_summary[-5:]) if error_summary else "No stderr output."
|
| 227 |
+
# Check specifically for import errors within the subprocess stderr
|
| 228 |
+
if "ModuleNotFoundError: No module named 'src'" in e.stderr:
|
| 229 |
+
raise gr.Error(f"Error in UniRig '{step_name}': Script failed to import the 'src' module. Check PYTHONPATH and script CWD.")
|
| 230 |
+
elif "ModuleNotFoundError: No module named 'bpy'" in e.stderr:
|
| 231 |
raise gr.Error(f"Error in UniRig '{step_name}': Blender failed to provide 'bpy' module internally.")
|
| 232 |
elif "ImportError: Failed to load PyTorch C extensions" in e.stderr:
|
| 233 |
raise gr.Error(f"Error in UniRig '{step_name}': Script failed to load PyTorch extensions even within Blender. Check installation.")
|
|
|
|
| 281 |
abs_final_rigged_glb_path = os.path.join(processing_temp_dir, f"{base_name}_rigged_final.glb")
|
| 282 |
|
| 283 |
# --- Define Absolute Paths to UniRig PYTHON Scripts ---
|
| 284 |
+
# *** Assuming run.py is the correct entry point. VERIFY THIS. ***
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
run_script_path = os.path.join(UNIRIG_REPO_DIR, "run.py") # Main script?
|
| 286 |
|
| 287 |
# --- Execute UniRig Steps ---
|
|
|
|
| 289 |
# Step 1: Skeleton Prediction
|
| 290 |
print("\nStarting Step 1: Predicting Skeleton...")
|
| 291 |
# Arguments for the run.py script for skeleton task
|
| 292 |
+
# ** These are GUESSES - VERIFY from UniRig code / shell scripts **
|
| 293 |
skeleton_args = [
|
| 294 |
+
# "--task", "generate_skeleton", # Example: if run.py needs a task identifier
|
|
|
|
| 295 |
"--input", abs_input_glb_path,
|
| 296 |
"--output", abs_skeleton_output_path
|
|
|
|
| 297 |
]
|
| 298 |
+
if not os.path.exists(run_script_path):
|
| 299 |
raise gr.Error(f"UniRig main script not found at: {run_script_path}")
|
|
|
|
| 300 |
run_unirig_command(run_script_path, skeleton_args, "Skeleton Prediction")
|
| 301 |
if not os.path.exists(abs_skeleton_output_path):
|
| 302 |
raise gr.Error("Skeleton prediction failed. Output file not created. Check logs.")
|
|
|
|
| 305 |
# Step 2: Skinning Weight Prediction
|
| 306 |
print("\nStarting Step 2: Predicting Skinning Weights...")
|
| 307 |
# Arguments for the run.py script for skinning task
|
| 308 |
+
# ** GUESSES - VERIFY **
|
| 309 |
skin_args = [
|
| 310 |
+
# "--task", "generate_skin",
|
| 311 |
+
"--input", abs_skeleton_output_path,
|
| 312 |
+
"--source", abs_input_glb_path,
|
| 313 |
"--output", abs_skin_output_path
|
| 314 |
]
|
| 315 |
run_unirig_command(run_script_path, skin_args, "Skinning Prediction")
|
|
|
|
| 320 |
# Step 3: Merge Skeleton/Skin with Original Mesh
|
| 321 |
print("\nStarting Step 3: Merging Results...")
|
| 322 |
# Arguments for the run.py script for merging task
|
| 323 |
+
# ** GUESSES - VERIFY **
|
|
|
|
|
|
|
| 324 |
merge_args = [
|
| 325 |
+
# "--task", "merge",
|
| 326 |
"--source", abs_skin_output_path,
|
| 327 |
"--target", abs_input_glb_path,
|
| 328 |
"--output", abs_final_rigged_glb_path
|