File size: 1,415 Bytes
c10f4a4 555baa4 c10f4a4 fd0a6a1 555baa4 237c48a 555baa4 70f48cc de28594 237c48a de28594 237c48a c10f4a4 fd0a6a1 03b1ac5 fd0a6a1 70f48cc 237c48a fd0a6a1 eb9d32a 591abbb fd0a6a1 c10f4a4 |
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 |
import gradio as gr
import numpy as np
import imageio
def process_image(img):
imageio.imwrite("output_image.png", img["composite"])
alpha_channel = img["layers"][0][:, :, 3]
mask = np.where(alpha_channel == 0, 0, 255)
# mask = np.where(alpha_channel == 0, 0, 255).astype(np.uint8)
# return img["background"], mask
# Save the mask as a PNG file
# output_path = "mask_output.png"
# imageio.imwrite(output_path, mask) # Save the mask as a PNG
return 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])
# Define the Gradio interface
demo = gr.Interface(
fn=process_image,
inputs=gr.ImageMask(sources=["upload"], layers=False, transforms=[], format="png", label="base image", show_label=True),
outputs=[
# gr.Image(label="Background Image"),
gr.Image(label="Mask Image", format="png"),
],
description="Upload an image and then draw mask on the image selecting Pen icon!",
article = "For Auto text guided Mask generation, try @ovi054's [Text Guided Inpainting Mask tool](https://huggingface.co/spaces/ovi054/text-guided-mask-for-inpainting)"
)
demo.launch(debug=True) |