BraUndress's picture
Update app.py
85f151f verified
raw
history blame
No virus
1.37 kB
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)