jbilcke-hf HF staff commited on
Commit
dc16672
·
verified ·
1 Parent(s): 4b4ce8a

Update gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +8 -10
gradio_app.py CHANGED
@@ -190,17 +190,11 @@ def generate_and_process_3d(prompt: str, seed: int = 42, width: int = 1024, heig
190
  rgb_image = generated_image.convert('RGB')
191
 
192
  print("[debug] removing the background by calling bg_remover.process(rgb_image)")
 
193
  no_bg_image = bg_remover.process(rgb_image)
194
 
195
- print("[debug] converting to numpy array to extract the mask")
196
- no_bg_array = np.array(no_bg_image)
197
-
198
- # Create mask based on RGB values
199
- mask = ((no_bg_array > 0).any(axis=2)).astype(np.float32)
200
- mask = np.expand_dims(mask, axis=2) # Add channel dimension
201
-
202
- print("[debug] creating the RGBA image using create_rgba_image(rgb_image, mask)")
203
- rgba_image = create_rgba_image(rgb_image, mask)
204
 
205
  print("[debug] auto-cropping the rgba_image using spar3d_utils.foreground_crop(...)")
206
  processed_image = spar3d_utils.foreground_crop(
@@ -209,6 +203,10 @@ def generate_and_process_3d(prompt: str, seed: int = 42, width: int = 1024, heig
209
  newsize=(COND_WIDTH, COND_HEIGHT),
210
  no_crop=False
211
  )
 
 
 
 
212
 
213
  # Prepare batch for processing
214
  print("[debug] preparing the batch by calling create_batch(processed_image)")
@@ -253,7 +251,7 @@ def generate_and_process_3d(prompt: str, seed: int = 42, width: int = 1024, heig
253
  import traceback
254
  traceback.print_exc()
255
  return None, None
256
-
257
  # Create Gradio interface
258
  demo = gr.Interface(
259
  fn=generate_and_process_3d,
 
190
  rgb_image = generated_image.convert('RGB')
191
 
192
  print("[debug] removing the background by calling bg_remover.process(rgb_image)")
193
+ # The key change: Process returns RGBA with transparent background
194
  no_bg_image = bg_remover.process(rgb_image)
195
 
196
+ # Convert the no_bg_image directly to RGBA (it should already be RGBA)
197
+ rgba_image = Image.fromarray(no_bg_image).convert('RGBA')
 
 
 
 
 
 
 
198
 
199
  print("[debug] auto-cropping the rgba_image using spar3d_utils.foreground_crop(...)")
200
  processed_image = spar3d_utils.foreground_crop(
 
203
  newsize=(COND_WIDTH, COND_HEIGHT),
204
  no_crop=False
205
  )
206
+
207
+ # Show the processed image alpha channel for debugging
208
+ alpha = np.array(processed_image)[:, :, 3]
209
+ print(f"[debug] Alpha channel stats - min: {alpha.min()}, max: {alpha.max()}, unique: {np.unique(alpha)}")
210
 
211
  # Prepare batch for processing
212
  print("[debug] preparing the batch by calling create_batch(processed_image)")
 
251
  import traceback
252
  traceback.print_exc()
253
  return None, None
254
+
255
  # Create Gradio interface
256
  demo = gr.Interface(
257
  fn=generate_and_process_3d,