BraUndress commited on
Commit
e369f8f
1 Parent(s): 1ec6a79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -1,27 +1,22 @@
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
- label_text = """This page is only used to generate MASK mask images and cannot be used to submit tasks.
10
- 本页面仅用于生成MASK遮罩图片,无法用于提交任务
11
- Click the RUN button to generate a MASK IMAGE and send it back to the BRAUNDRESS bot
12
- 点击RUN按钮生成MASK IMAGE后将其发送回BRAUNDRESS机器人"""
13
- gr.Label(label_text, font_size=16, font_family="Arial", padding=10)
14
- backup_url_text = "backup mask maker: https://huggingface.co/spaces/stevhliu/inpaint-mask-maker https://huggingface.co/spaces/r3gm/inpaint-mask-maker https://huggingface.co/spaces/daethyra/inpaint-mask-maker"
15
- gr.Label(backup_url_text, font_size=10, font_family="Arial", padding=10)
16
- with gr.Row():
17
- img = gr.Image(
18
- tool="sketch", label="base image", show_label=True,
19
- style={"height": "500px", "max-width": "100%", "@media (max-width: 768px)": {"height": "300px"}}
20
- )
21
  with gr.Row():
22
- img1 = gr.Image()
23
  img2 = gr.Image(label="mask image", show_label=True)
24
- btn = gr.Button()
25
- btn.click(dummy, img, [img1, img2])
26
 
27
- demo.launch(debug=True)
 
1
  import gradio as gr
2
+ import numpy as np
3
  import imageio
4
 
5
  def dummy(img):
6
+ # Assuming img is a dictionary with keys 'composite', 'background', and 'layers'
7
+ composite_image = img["composite"]
8
+ imageio.imwrite("output_image.png", composite_image)
9
+
10
+ alpha_channel = img["layers"][0][:, :, 3]
11
+ mask = np.where(alpha_channel == 0, 0, 255).astype(np.uint8)
12
+
13
+ return mask
14
 
15
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
16
  with gr.Row():
17
+ img = gr.ImageMask(sources=["upload"], layers=True, transforms=[], format="png", label="base image", show_label=True)
18
  img2 = gr.Image(label="mask image", show_label=True)
19
+ btn = gr.Button("Generate Mask")
20
+ btn.click(dummy, inputs=img, outputs=img2)
21
 
22
+ demo.launch(debug=True)