leoeric commited on
Commit
0ce71e8
Β·
1 Parent(s): 02a442c

Add log file generation for debugging

Browse files
Files changed (1) hide show
  1. app.py +37 -2
app.py CHANGED
@@ -153,11 +153,41 @@ def generate_image(prompt, aspect_ratio, cfg, seed, checkpoint_file, config_path
153
  status_msg += "Running generation...\n"
154
  status_msg += "Note: First run includes checkpoint download (~10-20 min) and model loading (~2-5 min).\n"
155
 
 
 
 
 
156
  # Run with timeout (45 minutes max - allows for download + generation)
157
- result = subprocess.run(cmd, capture_output=True, text=True, cwd=os.getcwd(), timeout=2700)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  if result.returncode != 0:
160
  error_msg = f"Error during generation:\n{result.stderr}\n\nStdout:\n{result.stdout}"
 
 
161
  return None, error_msg
162
 
163
  status_msg += "Generation complete. Looking for output...\n"
@@ -170,7 +200,12 @@ def generate_image(prompt, aspect_ratio, cfg, seed, checkpoint_file, config_path
170
  latest_file = max(output_files, key=lambda p: p.stat().st_mtime)
171
  return str(latest_file), status_msg + "βœ… Success! Image generated."
172
  else:
173
- return None, status_msg + f"Error: Generated image not found in {output_dir}. Check stdout:\n{result.stdout}"
 
 
 
 
 
174
 
175
  except Exception as e:
176
  return None, f"Error: {str(e)}"
 
153
  status_msg += "Running generation...\n"
154
  status_msg += "Note: First run includes checkpoint download (~10-20 min) and model loading (~2-5 min).\n"
155
 
156
+ # Create log file for debugging
157
+ log_file = output_dir / "generation.log"
158
+ status_msg += f"πŸ“‹ Logs will be saved to: {log_file}\n"
159
+
160
  # Run with timeout (45 minutes max - allows for download + generation)
161
+ # Capture output and write to log file
162
+ result = subprocess.run(
163
+ cmd,
164
+ capture_output=True,
165
+ text=True,
166
+ cwd=os.getcwd(),
167
+ timeout=2700
168
+ )
169
+
170
+ # Write to log file
171
+ with open(log_file, 'w') as log:
172
+ log.write("=== GENERATION LOG ===\n\n")
173
+ log.write(f"Command: {' '.join(cmd)}\n\n")
174
+ log.write("=== STDOUT ===\n")
175
+ log.write(result.stdout)
176
+ log.write("\n\n=== STDERR ===\n")
177
+ log.write(result.stderr)
178
+ log.write(f"\n\n=== RETURN CODE: {result.returncode} ===\n")
179
+
180
+ # Read log file for detailed output
181
+ log_content = ""
182
+ if log_file.exists():
183
+ with open(log_file, 'r') as f:
184
+ log_content = f.read()
185
+ status_msg += f"\nπŸ“‹ Full logs available at: {log_file}\n"
186
 
187
  if result.returncode != 0:
188
  error_msg = f"Error during generation:\n{result.stderr}\n\nStdout:\n{result.stdout}"
189
+ if log_content:
190
+ error_msg += f"\n\nπŸ“‹ Full log file ({log_file}):\n{log_content[-2000:]}" # Last 2000 chars
191
  return None, error_msg
192
 
193
  status_msg += "Generation complete. Looking for output...\n"
 
200
  latest_file = max(output_files, key=lambda p: p.stat().st_mtime)
201
  return str(latest_file), status_msg + "βœ… Success! Image generated."
202
  else:
203
+ error_msg = status_msg + f"Error: Generated image not found in {output_dir}."
204
+ if log_content:
205
+ error_msg += f"\n\nπŸ“‹ Check log file for details: {log_file}\nLast 1000 chars:\n{log_content[-1000:]}"
206
+ else:
207
+ error_msg += f"\n\nCheck stdout:\n{result.stdout}"
208
+ return None, error_msg
209
 
210
  except Exception as e:
211
  return None, f"Error: {str(e)}"