Spaces:
Running
Running
ritwikraha
commited on
chore: updates to app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
with gr.Blocks() as demo:
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
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)
|