ritwikraha's picture
chore: updates to app.py
56f16c7 verified
raw
history blame
779 Bytes
import gradio as gr
import cv2
def create_mask(image):
# Convert image to grayscale for easier segmentation
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply thresholding to create a binary mask (adjust threshold value as needed)
_, mask = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
return mask
with gr.Blocks() as demo:
gr.Markdown(
"""
# Image Mask Creator
Draw on the image to create a mask.
"""
)
with gr.Row():
base_image = gr.Image(tool="sketch", label="Base Image", width=512, height=512, show_label=True)
mask_image = gr.Image(label="Mask Image", show_label=True)
btn = gr.Button("Create Mask")
btn.click(create_mask, inputs=base_image, outputs=mask_image)
demo.launch(debug=True)