amaye15
commited on
Commit
·
83a9ebc
1
Parent(s):
a4d9321
point prompt
Browse files- app.py +48 -30
- requirements.txt +4 -0
app.py
CHANGED
@@ -1,34 +1,52 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from
|
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 |
# Launch the Gradio app
|
34 |
-
|
|
|
|
1 |
+
import cv2
|
2 |
import gradio as gr
|
3 |
+
from gradio_point_promptable_image import PointPromptableImage
|
4 |
+
|
5 |
+
# Define the colors to use for marking points
|
6 |
+
BLUE = (135, 206, 235)
|
7 |
+
PINK = (239, 149, 186)
|
8 |
+
|
9 |
+
|
10 |
+
# Function to extract specific point inputs based on criteria
|
11 |
+
def get_point_inputs(prompts):
|
12 |
+
point_inputs = []
|
13 |
+
for prompt in prompts:
|
14 |
+
# Example condition to filter points (you can adjust this)
|
15 |
+
if prompt[5] == 4.0: # Checks for a specific condition in the prompts
|
16 |
+
point_inputs.append((prompt[0], prompt[1], prompt[2]))
|
17 |
+
return point_inputs
|
18 |
+
|
19 |
+
|
20 |
+
# Function to process the image and mark points based on user input
|
21 |
+
def process_input(input_dict):
|
22 |
+
img, points = input_dict["image"], input_dict["points"]
|
23 |
+
|
24 |
+
# Extract points from user input
|
25 |
+
point_inputs = get_point_inputs(points)
|
26 |
+
|
27 |
+
# Mark the points on the image
|
28 |
+
for point in point_inputs:
|
29 |
+
x, y = int(point[0]), int(point[1])
|
30 |
+
cv2.circle(
|
31 |
+
img, (x, y), 2, (0, 0, 0), thickness=10
|
32 |
+
) # Black border for visibility
|
33 |
+
if point[2] == 1:
|
34 |
+
cv2.circle(img, (x, y), 2, BLUE, thickness=8) # Blue for class 1
|
35 |
+
else:
|
36 |
+
cv2.circle(img, (x, y), 2, PINK, thickness=8) # Pink for other classes
|
37 |
+
|
38 |
+
return img # Return the image with the points marked
|
39 |
+
|
40 |
+
|
41 |
+
# Create the Gradio interface with an uploadable image
|
42 |
+
demo = gr.Interface(
|
43 |
+
process_input, # The function to process the input image and points
|
44 |
+
PointPromptableImage(), # Custom input component to get points from the user
|
45 |
+
gr.Image(), # Output component to display the processed image
|
46 |
+
title="Image Upload and Point Marker",
|
47 |
+
description="Upload an image, click on it to mark points, and see the points marked.",
|
48 |
)
|
49 |
|
50 |
# Launch the Gradio app
|
51 |
+
if __name__ == "__main__":
|
52 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
pillow
|
3 |
+
gradio-point-promptable-image
|
4 |
+
opencv-python
|