Spaces:
Running
on
Zero
Running
on
Zero
Improve error handling to show full error details and tracebacks in UI
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ import gradio as gr
|
|
| 18 |
import torch
|
| 19 |
import subprocess
|
| 20 |
import pathlib
|
|
|
|
| 21 |
from pathlib import Path
|
| 22 |
|
| 23 |
# Suppress harmless warnings
|
|
@@ -249,9 +250,17 @@ def _generate_image_impl(prompt, aspect_ratio, cfg, seed, checkpoint_file, confi
|
|
| 249 |
status_msg += f"\nπ Full logs available at: {log_file}\n"
|
| 250 |
|
| 251 |
if result.returncode != 0:
|
| 252 |
-
error_msg = f"Error during generation
|
|
|
|
|
|
|
| 253 |
if log_content:
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
return None, error_msg
|
| 256 |
|
| 257 |
status_msg += "Generation complete. Looking for output...\n"
|
|
@@ -304,7 +313,13 @@ def _generate_image_impl(prompt, aspect_ratio, cfg, seed, checkpoint_file, confi
|
|
| 304 |
return None, error_msg
|
| 305 |
|
| 306 |
except Exception as e:
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
|
| 310 |
# Apply @spaces.GPU decorator if available (required for ZeroGPU)
|
|
@@ -384,7 +399,10 @@ def _generate_video_impl(prompt, aspect_ratio, cfg, seed, target_length, checkpo
|
|
| 384 |
result = subprocess.run(cmd, capture_output=True, text=True, cwd=os.getcwd())
|
| 385 |
|
| 386 |
if result.returncode != 0:
|
| 387 |
-
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
# Find the generated video
|
| 390 |
output_files = list(output_dir.glob("**/*.mp4")) + list(output_dir.glob("**/*.gif"))
|
|
@@ -395,7 +413,13 @@ def _generate_video_impl(prompt, aspect_ratio, cfg, seed, target_length, checkpo
|
|
| 395 |
return None, "Error: Generated video not found."
|
| 396 |
|
| 397 |
except Exception as e:
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
|
| 401 |
# Create Gradio interface
|
|
|
|
| 18 |
import torch
|
| 19 |
import subprocess
|
| 20 |
import pathlib
|
| 21 |
+
import traceback
|
| 22 |
from pathlib import Path
|
| 23 |
|
| 24 |
# Suppress harmless warnings
|
|
|
|
| 250 |
status_msg += f"\nπ Full logs available at: {log_file}\n"
|
| 251 |
|
| 252 |
if result.returncode != 0:
|
| 253 |
+
error_msg = f"β Error during generation (return code: {result.returncode})\n\n"
|
| 254 |
+
error_msg += f"=== STDERR ===\n{result.stderr}\n\n"
|
| 255 |
+
error_msg += f"=== STDOUT ===\n{result.stdout}\n\n"
|
| 256 |
if log_content:
|
| 257 |
+
# Show last 3000 chars of log for more context
|
| 258 |
+
error_msg += f"π Last 3000 characters from log file ({log_file}):\n"
|
| 259 |
+
error_msg += f"{'='*60}\n"
|
| 260 |
+
error_msg += log_content[-3000:]
|
| 261 |
+
error_msg += f"\n{'='*60}\n"
|
| 262 |
+
else:
|
| 263 |
+
error_msg += f"β οΈ Log file not found at: {log_file}\n"
|
| 264 |
return None, error_msg
|
| 265 |
|
| 266 |
status_msg += "Generation complete. Looking for output...\n"
|
|
|
|
| 313 |
return None, error_msg
|
| 314 |
|
| 315 |
except Exception as e:
|
| 316 |
+
# Get full traceback for debugging
|
| 317 |
+
error_traceback = traceback.format_exc()
|
| 318 |
+
error_msg = f"β Exception occurred during image generation:\n\n"
|
| 319 |
+
error_msg += f"Error Type: {type(e).__name__}\n"
|
| 320 |
+
error_msg += f"Error Message: {str(e)}\n\n"
|
| 321 |
+
error_msg += f"=== FULL TRACEBACK ===\n{error_traceback}\n"
|
| 322 |
+
return None, error_msg
|
| 323 |
|
| 324 |
|
| 325 |
# Apply @spaces.GPU decorator if available (required for ZeroGPU)
|
|
|
|
| 399 |
result = subprocess.run(cmd, capture_output=True, text=True, cwd=os.getcwd())
|
| 400 |
|
| 401 |
if result.returncode != 0:
|
| 402 |
+
error_msg = f"β Error during video generation (return code: {result.returncode})\n\n"
|
| 403 |
+
error_msg += f"=== STDERR ===\n{result.stderr}\n\n"
|
| 404 |
+
error_msg += f"=== STDOUT ===\n{result.stdout}\n"
|
| 405 |
+
return None, error_msg
|
| 406 |
|
| 407 |
# Find the generated video
|
| 408 |
output_files = list(output_dir.glob("**/*.mp4")) + list(output_dir.glob("**/*.gif"))
|
|
|
|
| 413 |
return None, "Error: Generated video not found."
|
| 414 |
|
| 415 |
except Exception as e:
|
| 416 |
+
# Get full traceback for debugging
|
| 417 |
+
error_traceback = traceback.format_exc()
|
| 418 |
+
error_msg = f"β Exception occurred during video generation:\n\n"
|
| 419 |
+
error_msg += f"Error Type: {type(e).__name__}\n"
|
| 420 |
+
error_msg += f"Error Message: {str(e)}\n\n"
|
| 421 |
+
error_msg += f"=== FULL TRACEBACK ===\n{error_traceback}\n"
|
| 422 |
+
return None, error_msg
|
| 423 |
|
| 424 |
|
| 425 |
# Create Gradio interface
|