Spaces:
Running
on
Zero
Running
on
Zero
Improve error messages and add status updates for long-running operations
Browse files
app.py
CHANGED
|
@@ -60,12 +60,16 @@ def get_checkpoint_path(checkpoint_file, default_local_path, repo_id=None, filen
|
|
| 60 |
repo_id=repo_id,
|
| 61 |
filename=filename,
|
| 62 |
cache_dir=cache_dir,
|
| 63 |
-
local_files_only=False
|
|
|
|
| 64 |
)
|
| 65 |
print(f"✅ Checkpoint downloaded to: {checkpoint_path}")
|
| 66 |
return checkpoint_path
|
| 67 |
except Exception as e:
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# No checkpoint found
|
| 71 |
return None, f"Checkpoint not found. Please upload a checkpoint file or configure Model Hub repository."
|
|
@@ -92,12 +96,19 @@ def generate_image(prompt, aspect_ratio, cfg, seed, checkpoint_file, config_path
|
|
| 92 |
return None, result[1] # Error message
|
| 93 |
|
| 94 |
checkpoint_path = result
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
if not os.path.exists(checkpoint_path):
|
| 96 |
-
return None, f"Error: Checkpoint file not found at {checkpoint_path}."
|
| 97 |
|
| 98 |
if not config_path or not os.path.exists(config_path):
|
| 99 |
return None, "Error: Config file not found. Please ensure config file exists."
|
| 100 |
|
|
|
|
|
|
|
|
|
|
| 101 |
try:
|
| 102 |
# Create output directory
|
| 103 |
output_dir = Path("outputs")
|
|
@@ -120,10 +131,16 @@ def generate_image(prompt, aspect_ratio, cfg, seed, checkpoint_file, config_path
|
|
| 120 |
"--jacobi_block_size", "16"
|
| 121 |
]
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
if result.returncode != 0:
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
# Find the generated image
|
| 129 |
# The sample.py script saves to logdir/model_name/...
|
|
@@ -131,9 +148,9 @@ def generate_image(prompt, aspect_ratio, cfg, seed, checkpoint_file, config_path
|
|
| 131 |
output_files = list(output_dir.glob("**/*.png")) + list(output_dir.glob("**/*.jpg"))
|
| 132 |
if output_files:
|
| 133 |
latest_file = max(output_files, key=lambda p: p.stat().st_mtime)
|
| 134 |
-
return str(latest_file), "Success! Image generated."
|
| 135 |
else:
|
| 136 |
-
return None, "Error: Generated image not found."
|
| 137 |
|
| 138 |
except Exception as e:
|
| 139 |
return None, f"Error: {str(e)}"
|
|
|
|
| 60 |
repo_id=repo_id,
|
| 61 |
filename=filename,
|
| 62 |
cache_dir=cache_dir,
|
| 63 |
+
local_files_only=False,
|
| 64 |
+
resume_download=True # Resume if interrupted
|
| 65 |
)
|
| 66 |
print(f"✅ Checkpoint downloaded to: {checkpoint_path}")
|
| 67 |
return checkpoint_path
|
| 68 |
except Exception as e:
|
| 69 |
+
error_detail = str(e)
|
| 70 |
+
if "404" in error_detail or "not found" in error_detail.lower():
|
| 71 |
+
return None, f"Checkpoint not found in Model Hub.\n\nPlease verify:\n1. Repo exists: https://huggingface.co/{repo_id}\n2. File exists: {filename}\n3. Repo is Public (not Private)\n\nError: {error_detail}"
|
| 72 |
+
return None, f"Error downloading checkpoint: {error_detail}\n\nThis may take 10-30 minutes for a 14GB file. Please wait or check your internet connection."
|
| 73 |
|
| 74 |
# No checkpoint found
|
| 75 |
return None, f"Checkpoint not found. Please upload a checkpoint file or configure Model Hub repository."
|
|
|
|
| 96 |
return None, result[1] # Error message
|
| 97 |
|
| 98 |
checkpoint_path = result
|
| 99 |
+
|
| 100 |
+
# Show status
|
| 101 |
+
status_msg = f"Using checkpoint: {checkpoint_path}\n"
|
| 102 |
+
|
| 103 |
if not os.path.exists(checkpoint_path):
|
| 104 |
+
return None, f"Error: Checkpoint file not found at {checkpoint_path}.\n\nPlease verify:\n1. Model Hub repo exists: {IMAGE_CHECKPOINT_REPO}\n2. File name matches: starflow_3B_t2i_256x256.pth\n3. Repo is Public (not Private)"
|
| 105 |
|
| 106 |
if not config_path or not os.path.exists(config_path):
|
| 107 |
return None, "Error: Config file not found. Please ensure config file exists."
|
| 108 |
|
| 109 |
+
status_msg += "Starting image generation...\n"
|
| 110 |
+
status_msg += "This may take 1-3 minutes for first run (model loading).\n"
|
| 111 |
+
|
| 112 |
try:
|
| 113 |
# Create output directory
|
| 114 |
output_dir = Path("outputs")
|
|
|
|
| 131 |
"--jacobi_block_size", "16"
|
| 132 |
]
|
| 133 |
|
| 134 |
+
status_msg += "Running generation...\n"
|
| 135 |
+
|
| 136 |
+
# Run with timeout (30 minutes max)
|
| 137 |
+
result = subprocess.run(cmd, capture_output=True, text=True, cwd=os.getcwd(), timeout=1800)
|
| 138 |
|
| 139 |
if result.returncode != 0:
|
| 140 |
+
error_msg = f"Error during generation:\n{result.stderr}\n\nStdout:\n{result.stdout}"
|
| 141 |
+
return None, error_msg
|
| 142 |
+
|
| 143 |
+
status_msg += "Generation complete. Looking for output...\n"
|
| 144 |
|
| 145 |
# Find the generated image
|
| 146 |
# The sample.py script saves to logdir/model_name/...
|
|
|
|
| 148 |
output_files = list(output_dir.glob("**/*.png")) + list(output_dir.glob("**/*.jpg"))
|
| 149 |
if output_files:
|
| 150 |
latest_file = max(output_files, key=lambda p: p.stat().st_mtime)
|
| 151 |
+
return str(latest_file), status_msg + "✅ Success! Image generated."
|
| 152 |
else:
|
| 153 |
+
return None, status_msg + f"Error: Generated image not found in {output_dir}. Check stdout:\n{result.stdout}"
|
| 154 |
|
| 155 |
except Exception as e:
|
| 156 |
return None, f"Error: {str(e)}"
|