amaye15 commited on
Commit
adf5040
·
1 Parent(s): a0761cf

point prompt

Browse files
Files changed (2) hide show
  1. app.py +17 -29
  2. requirments.txt +2 -0
app.py CHANGED
@@ -1,34 +1,22 @@
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 gradio as gr
2
+ from gradio_image_prompter import ImagePrompter
3
 
4
+ # Define the Gradio interface
5
+ demo = gr.Interface(
6
+ fn=lambda prompts: (
7
+ prompts["image"],
8
+ prompts["points"],
9
+ ), # Extract image and points from the ImagePrompter
10
+ inputs=ImagePrompter(
11
+ show_label=False
12
+ ), # ImagePrompter for image input and point selection
13
+ outputs=[
14
+ gr.Image(show_label=False),
15
+ gr.Dataframe(label="Points"),
16
+ ], # Outputs: Image and DataFrame of points
17
+ title="Image Point Collector",
18
+ description="Upload an image, click on it, and get the coordinates of the clicked points.",
 
 
 
 
 
 
 
 
 
 
 
 
19
  )
20
 
21
  # Launch the Gradio app
22
+ demo.launch()
requirments.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ gradio_image_prompter