ritwikraha commited on
Commit
56f16c7
·
verified ·
1 Parent(s): c4497cb

chore: updates to app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -1,23 +1,28 @@
1
  import gradio as gr
2
- import imageio
3
 
4
- def dummy(img):
5
- imageio.imwrite("output_image.png", img["mask"])
6
- return img["image"], img["mask"]
 
 
 
 
 
7
 
8
  with gr.Blocks() as demo:
9
- gr.Markdown(
10
- """
11
- # Image mask creator
12
- This is a demo of a simple image mask creator. You can draw on the image and the mask will be created.
13
- """
14
- )
 
 
 
 
15
 
16
- with gr.Row():
17
- img = gr.Image(tool="sketch", label="base image", width=512, height=512, show_label=True)
18
- img1 = gr.Image()
19
- img2 = gr.Image(label="mask image", show_label=True)
20
- btn = gr.Button()
21
- btn.click(dummy, img, [img1, img2])
22
 
23
  demo.launch(debug=True)
 
1
  import gradio as gr
2
+ import cv2
3
 
4
+ def create_mask(image):
5
+ # Convert image to grayscale for easier segmentation
6
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
7
+
8
+ # Apply thresholding to create a binary mask (adjust threshold value as needed)
9
+ _, mask = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
10
+
11
+ return mask
12
 
13
  with gr.Blocks() as demo:
14
+ gr.Markdown(
15
+ """
16
+ # Image Mask Creator
17
+ Draw on the image to create a mask.
18
+ """
19
+ )
20
+
21
+ with gr.Row():
22
+ base_image = gr.Image(tool="sketch", label="Base Image", width=512, height=512, show_label=True)
23
+ mask_image = gr.Image(label="Mask Image", show_label=True)
24
 
25
+ btn = gr.Button("Create Mask")
26
+ btn.click(create_mask, inputs=base_image, outputs=mask_image)
 
 
 
 
27
 
28
  demo.launch(debug=True)