amaye15 commited on
Commit
83a9ebc
·
1 Parent(s): a4d9321

point prompt

Browse files
Files changed (2) hide show
  1. app.py +48 -30
  2. requirements.txt +4 -0
app.py CHANGED
@@ -1,34 +1,52 @@
 
1
  import gradio as gr
2
- from PIL import Image, ImageDraw
3
-
4
-
5
- # Define a function that marks the clicked point on the image
6
- def mark_point(image, x, y):
7
- # Convert the Gradio image to a PIL Image
8
- img = Image.fromarray(image)
9
-
10
- # Draw a red circle at the clicked point
11
- draw = ImageDraw.Draw(img)
12
- radius = 5
13
- draw.ellipse(
14
- (x - radius, y - radius, x + radius, y + radius), fill="red", outline="red"
15
- )
16
-
17
- return img
18
-
19
-
20
- # Create the Gradio interface
21
- iface = gr.Interface(
22
- fn=mark_point, # The function that marks the point on the image
23
- inputs=[
24
- gr.Image(type="numpy", interactive=True),
25
- gr.Number(),
26
- gr.Number(),
27
- ], # Image input and coordinates
28
- outputs="image", # The output will be an image with the point marked
29
- title="Image Point Marker",
30
- description="Upload an image, click on it, and see the point marked.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  )
32
 
33
  # Launch the Gradio app
34
- iface.launch()
 
 
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