Spaces:
Running
Running
import gradio as gr | |
import numpy as np | |
import imageio | |
def dummy(img): | |
imageio.imwrite("output_image.png", img["composite"]) | |
alpha_channel = img["layers"][0][:, :, 3] | |
mask = np.where(alpha_channel == 0, 0, 255) | |
return img["background"], mask | |
with gr.Blocks() as demo: | |
with gr.Row(): | |
img = gr.ImageMask(sources=["upload"], layers=False, transforms=[], format="png", label="base image", show_label=True) | |
img1 = gr.Image() | |
img2 = gr.Image(label="mask image", show_label=True) | |
btn = gr.Button() | |
btn.click(dummy, img, [img1, img2]) | |
demo.launch(debug=True) |