add inpaint option

#1
by linoyts HF Staff - opened
Files changed (1) hide show
  1. app.py +29 -4
app.py CHANGED
@@ -361,8 +361,33 @@ def process(input_image, prompt,
361
  if t2v:
362
  default_height, default_width = 640, 640
363
  input_image = np.ones((default_height, default_width, 3), dtype=np.uint8) * 255
364
- print("No input image provided. Using a blank white image.")
365
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  yield None, None, '', '', gr.update(interactive=False), gr.update(interactive=True)
367
 
368
  stream = AsyncStream()
@@ -404,12 +429,12 @@ with block:
404
  gr.Markdown('# FramePack-F1')
405
  gr.Markdown(f"""### Video diffusion, but feels like image diffusion
406
  *FramePack F1 - a FramePack model that only predicts future frames from history frames*
407
-
408
  adapted from the officical code repo [FramePack](https://github.com/lllyasviel/FramePack) by [lllyasviel](lllyasviel/FramePack_F1_I2V_HY_20250503) and [FramePack Studio](https://github.com/colinurbs/FramePack-Studio) πŸ™ŒπŸ»
409
  """)
410
  with gr.Row():
411
  with gr.Column():
412
- input_image = gr.Image(type="numpy", label="Image", height=320)
413
  prompt = gr.Textbox(label="Prompt", value='')
414
  t2v = gr.Checkbox(label="do text-to-video", value=False)
415
  example_quick_prompts = gr.Dataset(samples=quick_prompts, label='Quick List', samples_per_page=1000, components=[prompt])
 
361
  if t2v:
362
  default_height, default_width = 640, 640
363
  input_image = np.ones((default_height, default_width, 3), dtype=np.uint8) * 255
364
+ print("No input image provided. Using a blank white image.")
365
+ else:
366
+ composite_rgba_uint8 = input_image["composite"]
367
+
368
+ # rgb_uint8 will be (H, W, 3), dtype uint8
369
+ rgb_uint8 = composite_rgba_uint8[:, :, :3]
370
+ # mask_uint8 will be (H, W), dtype uint8
371
+ mask_uint8 = composite_rgba_uint8[:, :, 3]
372
+
373
+ # Create background
374
+ h, w = rgb_uint8.shape[:2]
375
+ # White background, (H, W, 3), dtype uint8
376
+ background_uint8 = np.full((h, w, 3), 255, dtype=np.uint8)
377
+
378
+ # Normalize mask to range [0.0, 1.0].
379
+ alpha_normalized_float32 = mask_uint8.astype(np.float32) / 255.0
380
+
381
+ # Expand alpha to 3 channels to match RGB images for broadcasting.
382
+ # alpha_mask_float32 will have shape (H, W, 3)
383
+ alpha_mask_float32 = np.stack([alpha_normalized_float32] * 3, axis=2)
384
+
385
+ # alpha blending
386
+ blended_image_float32 = rgb_uint8.astype(np.float32) * alpha_mask_float32 + \
387
+ background_uint8.astype(np.float32) * (1.0 - alpha_mask_float32)
388
+
389
+ input_image = np.clip(blended_image_float32, 0, 255).astype(np.uint8)
390
+
391
  yield None, None, '', '', gr.update(interactive=False), gr.update(interactive=True)
392
 
393
  stream = AsyncStream()
 
429
  gr.Markdown('# FramePack-F1')
430
  gr.Markdown(f"""### Video diffusion, but feels like image diffusion
431
  *FramePack F1 - a FramePack model that only predicts future frames from history frames*
432
+ ### *beta* FramePack Fill πŸ–‹οΈ- draw a mask over the input image to inpaint the video output
433
  adapted from the officical code repo [FramePack](https://github.com/lllyasviel/FramePack) by [lllyasviel](lllyasviel/FramePack_F1_I2V_HY_20250503) and [FramePack Studio](https://github.com/colinurbs/FramePack-Studio) πŸ™ŒπŸ»
434
  """)
435
  with gr.Row():
436
  with gr.Column():
437
+ input_image = gr.ImageEditor(type="numpy", label="Image", height=320)
438
  prompt = gr.Textbox(label="Prompt", value='')
439
  t2v = gr.Checkbox(label="do text-to-video", value=False)
440
  example_quick_prompts = gr.Dataset(samples=quick_prompts, label='Quick List', samples_per_page=1000, components=[prompt])