File size: 1,365 Bytes
c10f4a4
e369f8f
43a0f6b
c10f4a4
 
e369f8f
 
 
 
 
 
 
 
4d156c6
85f151f
 
 
 
 
 
 
 
 
 
c10f4a4
85f151f
51b2b94
85f151f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c10f4a4
85f151f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
import numpy as np
import imageio

def dummy(img):
    # Assuming img is a dictionary with keys 'composite', 'background', and 'layers'
    composite_image = img["composite"]
    imageio.imwrite("output_image.png", composite_image)

    alpha_channel = img["layers"][0][:, :, 3]
    mask = np.where(alpha_channel == 0, 0, 255).astype(np.uint8)

    return mask

announcement = """
## Backup Inpaint Mask Maker:
备用蒙版工具: [Visit Here](https://huggingface.co/spaces/BraUndress/inpaint-mask-maker2)

## How to use:
使用方法: [Learn More](https://telegra.ph/HowToUploadMaskOnBraundress-05-01)

Source: BraUndress
"""

with gr.Blocks() as demo:
    # 将公告栏放在一个单独的Column中
    with gr.Row():
        with gr.Column():
            announcement = gr.Markdown(announcement)
    
    # 创建一个新的Column来放置ImageMask和按钮
    with gr.Column():
        with gr.Row():
            img = gr.ImageMask(
                sources=["upload"], 
                layers=True, 
                transforms=[], 
                format="png", 
                label="base image", 
                show_label=True
            )
            img2 = gr.Image(label="mask image", show_label=True)
        
        btn = gr.Button("Generate Mask")
        btn.click(dummy, inputs=img, outputs=img2)

demo.launch(debug=True)