Gan Tu commited on
Commit
9e9846f
·
1 Parent(s): 8175c50
Files changed (2) hide show
  1. app.py +22 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+
4
+ def create_mask(img):
5
+ alpha_channel = img["layers"][0][:, :, 3]
6
+ mask = np.where(alpha_channel == 0, 0, 255)
7
+ return mask
8
+
9
+ with gr.Blocks(title="In-Paint Mask Creator") as demo:
10
+ with gr.Row(equal_height=True):
11
+ img = gr.ImageMask(sources=["upload", "clipboard"],
12
+ layers=False,
13
+ transforms=[],
14
+ interactive=True,
15
+ format="png",
16
+ label="base image",
17
+ show_label=True)
18
+ mask_image = gr.Image(label="mask image", show_label=True)
19
+ btn = gr.Button("Create Mask")
20
+ btn.click(create_mask, img, mask_image)
21
+
22
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ numpy