luh1124 commited on
Commit
f996a94
Β·
1 Parent(s): 7b5d346

Load default image from assets in callbacks

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -359,6 +359,15 @@ def preprocess_image_only(img: Optional[Image.Image]) -> Optional[Image.Image]:
359
  return _preprocess_to_518(img)
360
 
361
 
 
 
 
 
 
 
 
 
 
362
  # ── SLaT I/O ──────────────────────────────────────────────────────────────────
363
 
364
  def _save_slat(slat: Any, path: Path) -> None:
@@ -428,12 +437,10 @@ def generate_geometry(
428
  progress: gr.Progress = gr.Progress(track_tqdm=True),
429
  ) -> tuple[Dict[str, Any], str, str]:
430
  """β‘  Hunyuan3D geometry generation."""
431
- if image_input is None:
432
- raise gr.Error("Upload an input image first.")
433
  session_dir = CACHE_DIR / str(req.session_hash)
434
  session_dir.mkdir(parents=True, exist_ok=True)
435
 
436
- rgba = _ensure_rgba(image_input)
437
  if rgba.size != (518, 518):
438
  progress(0.1, desc="Preprocessing image")
439
  rgba = _preprocess_to_518(rgba)
@@ -469,14 +476,12 @@ def generate_slat(
469
  mesh_path = asset_state.get("mesh_path")
470
  if not mesh_path or not os.path.isfile(mesh_path):
471
  raise gr.Error("Run **β‘  Geometry** first (or upload a mesh).")
472
- if image_input is None:
473
- raise gr.Error("Upload an input image.")
474
  session_dir = CACHE_DIR / str(req.session_hash)
475
 
476
  progress(0.1, desc="Loading mesh")
477
  mesh = trimesh.load(mesh_path, force="mesh")
478
 
479
- rgba = _ensure_rgba(image_input)
480
  if rgba.size != (518, 518):
481
  rgba = _preprocess_to_518(rgba)
482
  slat_img = _flatten_rgba(rgba, (0.0, 0.0, 0.0))
 
359
  return _preprocess_to_518(img)
360
 
361
 
362
+ def _resolve_input_image(image_input: Optional[Image.Image]) -> Image.Image:
363
+ """Use the bundled example directly from assets when no image is selected."""
364
+ if image_input is not None:
365
+ return image_input
366
+ if DEFAULT_IMAGE.exists() and not _path_is_git_lfs(DEFAULT_IMAGE):
367
+ return Image.open(DEFAULT_IMAGE).convert("RGBA")
368
+ raise gr.Error("Upload an input image first.")
369
+
370
+
371
  # ── SLaT I/O ──────────────────────────────────────────────────────────────────
372
 
373
  def _save_slat(slat: Any, path: Path) -> None:
 
437
  progress: gr.Progress = gr.Progress(track_tqdm=True),
438
  ) -> tuple[Dict[str, Any], str, str]:
439
  """β‘  Hunyuan3D geometry generation."""
 
 
440
  session_dir = CACHE_DIR / str(req.session_hash)
441
  session_dir.mkdir(parents=True, exist_ok=True)
442
 
443
+ rgba = _ensure_rgba(_resolve_input_image(image_input))
444
  if rgba.size != (518, 518):
445
  progress(0.1, desc="Preprocessing image")
446
  rgba = _preprocess_to_518(rgba)
 
476
  mesh_path = asset_state.get("mesh_path")
477
  if not mesh_path or not os.path.isfile(mesh_path):
478
  raise gr.Error("Run **β‘  Geometry** first (or upload a mesh).")
 
 
479
  session_dir = CACHE_DIR / str(req.session_hash)
480
 
481
  progress(0.1, desc="Loading mesh")
482
  mesh = trimesh.load(mesh_path, force="mesh")
483
 
484
+ rgba = _ensure_rgba(_resolve_input_image(image_input))
485
  if rgba.size != (518, 518):
486
  rgba = _preprocess_to_518(rgba)
487
  slat_img = _flatten_rgba(rgba, (0.0, 0.0, 0.0))