stevhliu HF staff commited on
Commit
555baa4
1 Parent(s): 4081588

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -1,13 +1,18 @@
1
  import gradio as gr
 
2
  import imageio
3
 
4
  def dummy(img):
5
- imageio.imwrite("output_image.png", img["mask"])
6
- return img["image"], img["mask"]
 
 
 
 
7
 
8
  with gr.Blocks() as demo:
9
  with gr.Row():
10
- img = gr.Image(tool="sketch", label="base image", show_label=True)
11
  img1 = gr.Image()
12
  img2 = gr.Image(label="mask image", show_label=True)
13
  btn = gr.Button()
 
1
  import gradio as gr
2
+ import numpy as np
3
  import imageio
4
 
5
  def dummy(img):
6
+ imageio.imwrite("output_image.png", img["composite"])
7
+
8
+ alpha_channel = img["layers"][0][:, :, 3]
9
+ mask = np.where(alpha_channel == 0, 0, 255)
10
+
11
+ return img["background"], mask
12
 
13
  with gr.Blocks() as demo:
14
  with gr.Row():
15
+ img = gr.ImageMask(sources=["upload"], layers=False, transforms=[], format="png", label="base image", show_label=True)
16
  img1 = gr.Image()
17
  img2 = gr.Image(label="mask image", show_label=True)
18
  btn = gr.Button()