ghmk commited on
Commit
dcf8aa7
·
1 Parent(s): c078ea1

Fix: Character Forge now completes with blank placeholders for failed images

Browse files

- Changed error handling to create grey placeholders instead of failing
- All 4 generated views (front/side portrait, side/rear body) use placeholders if API fails
- Character sheet will always complete, even if some images fail
- Fixes issue with Gemini API sometimes returning text instead of images

character_forge_image/services/character_forge_service.py CHANGED
@@ -180,8 +180,10 @@ class CharacterForgeService:
180
  )
181
 
182
  if front_portrait is None:
183
- logger.error(f"{current_stage} failed: {status}")
184
- return None, f"Stage 1 failed: {status}", {}
 
 
185
 
186
  logger.info(f"{current_stage} complete: {front_portrait.size}")
187
  stages['front_portrait'] = front_portrait
@@ -213,8 +215,10 @@ class CharacterForgeService:
213
  )
214
 
215
  if side_portrait is None:
216
- logger.error(f"{current_stage} failed: {status}")
217
- return None, f"Stage 2 failed: {status}", {}
 
 
218
 
219
  logger.info(f"{current_stage} complete: {side_portrait.size}")
220
  stages['side_portrait'] = side_portrait
@@ -241,8 +245,10 @@ class CharacterForgeService:
241
  )
242
 
243
  if side_body is None:
244
- logger.error(f"{current_stage} failed: {status}")
245
- return None, f"Stage 3 failed: {status}", {}
 
 
246
 
247
  logger.info(f"{current_stage} complete: {side_body.size}")
248
  stages['side_body'] = side_body
@@ -271,8 +277,10 @@ class CharacterForgeService:
271
  )
272
 
273
  if rear_body is None:
274
- logger.error(f"{current_stage} failed: {status}")
275
- return None, f"Stage 4 failed: {status}", {}
 
 
276
 
277
  logger.info(f"{current_stage} complete: {rear_body.size}")
278
  stages['rear_body'] = rear_body
 
180
  )
181
 
182
  if front_portrait is None:
183
+ logger.warning(f"{current_stage} failed: {status} - will use placeholder")
184
+ # Create blank placeholder (3:4 portrait aspect ratio = 864x1184)
185
+ front_portrait = Image.new('RGB', (864, 1184), color=(60, 60, 60))
186
+ status = f"Failed - using placeholder: {status}"
187
 
188
  logger.info(f"{current_stage} complete: {front_portrait.size}")
189
  stages['front_portrait'] = front_portrait
 
215
  )
216
 
217
  if side_portrait is None:
218
+ logger.warning(f"{current_stage} failed: {status} - will use placeholder")
219
+ # Create blank placeholder (3:4 portrait aspect ratio = 864x1184)
220
+ side_portrait = Image.new('RGB', (864, 1184), color=(60, 60, 60))
221
+ status = f"Failed - using placeholder: {status}"
222
 
223
  logger.info(f"{current_stage} complete: {side_portrait.size}")
224
  stages['side_portrait'] = side_portrait
 
245
  )
246
 
247
  if side_body is None:
248
+ logger.warning(f"{current_stage} failed: {status} - will use placeholder")
249
+ # Create blank placeholder (9:16 body aspect ratio = 768x1344)
250
+ side_body = Image.new('RGB', (768, 1344), color=(60, 60, 60))
251
+ status = f"Failed - using placeholder: {status}"
252
 
253
  logger.info(f"{current_stage} complete: {side_body.size}")
254
  stages['side_body'] = side_body
 
277
  )
278
 
279
  if rear_body is None:
280
+ logger.warning(f"{current_stage} failed: {status} - will use placeholder")
281
+ # Create blank placeholder (9:16 body aspect ratio = 768x1344)
282
+ rear_body = Image.new('RGB', (768, 1344), color=(60, 60, 60))
283
+ status = f"Failed - using placeholder: {status}"
284
 
285
  logger.info(f"{current_stage} complete: {rear_body.size}")
286
  stages['rear_body'] = rear_body