Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,9 @@ BLENDER_EXEC = os.path.join(BLENDER_INSTALL_DIR, "blender")
|
|
22 |
BLENDER_EXEC_SYMLINK = "/usr/local/bin/blender" # Fallback symlink
|
23 |
|
24 |
SETUP_SCRIPT = os.path.join(os.path.dirname(__file__), "setup_blender.sh")
|
|
|
|
|
|
|
25 |
|
26 |
# --- Initial Checks ---
|
27 |
print("--- Environment Checks ---")
|
@@ -37,7 +40,13 @@ else:
|
|
37 |
if os.path.exists(SETUP_SCRIPT):
|
38 |
try:
|
39 |
# Run setup script if Blender not found
|
40 |
-
setup_result = subprocess.run(
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
print("Setup script executed successfully.")
|
42 |
print(f"Setup STDOUT:\n{setup_result.stdout}")
|
43 |
if setup_result.stderr: print(f"Setup STDERR:\n{setup_result.stderr}")
|
@@ -55,8 +64,8 @@ else:
|
|
55 |
raise RuntimeError(f"Setup script ran but Blender executable still not found at {BLENDER_EXEC} or {BLENDER_EXEC_SYMLINK}.")
|
56 |
|
57 |
except subprocess.TimeoutExpired:
|
58 |
-
print(f"ERROR: Setup script timed out: {SETUP_SCRIPT}")
|
59 |
-
raise gr.Error("Setup script timed out. The Space might be too slow or setup is stuck.")
|
60 |
except subprocess.CalledProcessError as e:
|
61 |
print(f"ERROR running setup script: {SETUP_SCRIPT}\nStderr: {e.stderr}")
|
62 |
# Raise a Gradio error to notify the user
|
@@ -227,7 +236,7 @@ def run_unirig_command(python_script_path: str, script_args: List[str], step_nam
|
|
227 |
text=True,
|
228 |
check=True, # Raises CalledProcessError on non-zero exit codes
|
229 |
env=process_env, # Pass the modified environment
|
230 |
-
timeout=1800 # 30 minutes timeout
|
231 |
)
|
232 |
print(f"{step_name} STDOUT:\n{result.stdout}")
|
233 |
if result.stderr:
|
@@ -408,12 +417,14 @@ print("--- End Diagnostic Info ---")
|
|
408 |
# --- Execute UniRig Steps ---
|
409 |
# Step 1: Skeleton Prediction
|
410 |
print("\nStarting Step 1: Predicting Skeleton...")
|
|
|
411 |
skeleton_args = [
|
412 |
-
"--config-name=skeleton_config",
|
413 |
-
"with",
|
414 |
f"input={abs_input_glb_path}",
|
415 |
f"output={abs_skeleton_output_path}",
|
416 |
unirig_device_arg
|
|
|
417 |
]
|
418 |
run_unirig_command(unirig_script_to_run, skeleton_args, "Skeleton Prediction")
|
419 |
if not os.path.exists(abs_skeleton_output_path):
|
@@ -425,7 +436,7 @@ print("--- End Diagnostic Info ---")
|
|
425 |
skin_args = [
|
426 |
"--config-name=skin_config",
|
427 |
"with",
|
428 |
-
f"input={abs_skeleton_output_path}",
|
429 |
f"output={abs_skin_output_path}",
|
430 |
unirig_device_arg
|
431 |
]
|
@@ -439,10 +450,10 @@ print("--- End Diagnostic Info ---")
|
|
439 |
merge_args = [
|
440 |
"--config-name=merge_config",
|
441 |
"with",
|
442 |
-
f"source_path={abs_skin_output_path}",
|
443 |
-
f"target_path={abs_input_glb_path}",
|
444 |
f"output_path={abs_final_rigged_glb_path}",
|
445 |
-
"mode=skin",
|
446 |
unirig_device_arg
|
447 |
]
|
448 |
run_unirig_command(unirig_script_to_run, merge_args, "Merging Results")
|
|
|
22 |
BLENDER_EXEC_SYMLINK = "/usr/local/bin/blender" # Fallback symlink
|
23 |
|
24 |
SETUP_SCRIPT = os.path.join(os.path.dirname(__file__), "setup_blender.sh")
|
25 |
+
# ** INCREASED TIMEOUT FOR SETUP SCRIPT **
|
26 |
+
SETUP_SCRIPT_TIMEOUT = 1800 # 30 minutes (increased from 600 seconds)
|
27 |
+
|
28 |
|
29 |
# --- Initial Checks ---
|
30 |
print("--- Environment Checks ---")
|
|
|
40 |
if os.path.exists(SETUP_SCRIPT):
|
41 |
try:
|
42 |
# Run setup script if Blender not found
|
43 |
+
setup_result = subprocess.run(
|
44 |
+
["bash", SETUP_SCRIPT],
|
45 |
+
check=True,
|
46 |
+
capture_output=True,
|
47 |
+
text=True,
|
48 |
+
timeout=SETUP_SCRIPT_TIMEOUT # Use the increased timeout
|
49 |
+
)
|
50 |
print("Setup script executed successfully.")
|
51 |
print(f"Setup STDOUT:\n{setup_result.stdout}")
|
52 |
if setup_result.stderr: print(f"Setup STDERR:\n{setup_result.stderr}")
|
|
|
64 |
raise RuntimeError(f"Setup script ran but Blender executable still not found at {BLENDER_EXEC} or {BLENDER_EXEC_SYMLINK}.")
|
65 |
|
66 |
except subprocess.TimeoutExpired:
|
67 |
+
print(f"ERROR: Setup script timed out after {SETUP_SCRIPT_TIMEOUT} seconds: {SETUP_SCRIPT}")
|
68 |
+
raise gr.Error(f"Setup script timed out after {SETUP_SCRIPT_TIMEOUT // 60} minutes. The Space might be too slow or setup is stuck. Check full logs for the last operation.")
|
69 |
except subprocess.CalledProcessError as e:
|
70 |
print(f"ERROR running setup script: {SETUP_SCRIPT}\nStderr: {e.stderr}")
|
71 |
# Raise a Gradio error to notify the user
|
|
|
236 |
text=True,
|
237 |
check=True, # Raises CalledProcessError on non-zero exit codes
|
238 |
env=process_env, # Pass the modified environment
|
239 |
+
timeout=1800 # 30 minutes timeout for UniRig steps
|
240 |
)
|
241 |
print(f"{step_name} STDOUT:\n{result.stdout}")
|
242 |
if result.stderr:
|
|
|
417 |
# --- Execute UniRig Steps ---
|
418 |
# Step 1: Skeleton Prediction
|
419 |
print("\nStarting Step 1: Predicting Skeleton...")
|
420 |
+
# Arguments for run.py using Hydra format (key=value)
|
421 |
skeleton_args = [
|
422 |
+
"--config-name=skeleton_config", # Hydra main config
|
423 |
+
"with", # Hydra keyword for overrides
|
424 |
f"input={abs_input_glb_path}",
|
425 |
f"output={abs_skeleton_output_path}",
|
426 |
unirig_device_arg
|
427 |
+
# Add other args like "verbose=True" if needed for debugging
|
428 |
]
|
429 |
run_unirig_command(unirig_script_to_run, skeleton_args, "Skeleton Prediction")
|
430 |
if not os.path.exists(abs_skeleton_output_path):
|
|
|
436 |
skin_args = [
|
437 |
"--config-name=skin_config",
|
438 |
"with",
|
439 |
+
f"input={abs_skeleton_output_path}", # Input is the predicted skeleton
|
440 |
f"output={abs_skin_output_path}",
|
441 |
unirig_device_arg
|
442 |
]
|
|
|
450 |
merge_args = [
|
451 |
"--config-name=merge_config",
|
452 |
"with",
|
453 |
+
f"source_path={abs_skin_output_path}", # Merge skinned skeleton
|
454 |
+
f"target_path={abs_input_glb_path}", # With original mesh geometry/attrs
|
455 |
f"output_path={abs_final_rigged_glb_path}",
|
456 |
+
"mode=skin", # Specify merge mode
|
457 |
unirig_device_arg
|
458 |
]
|
459 |
run_unirig_command(unirig_script_to_run, merge_args, "Merging Results")
|