File size: 1,162 Bytes
f3004ad
adf5040
9afc623
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0761cf
adf5040
 
9afc623
adf5040
 
 
 
 
 
9afc623
 
 
63d8dec
 
 
adf5040
1
2
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
34
35
36
37
38
39
40
import gradio as gr
from gradio_image_prompter import ImagePrompter
from PIL import Image, ImageDraw


# Function to draw points on the image
def draw_points_on_image(prompts):
    image = Image.fromarray(prompts["image"])  # Convert numpy array to PIL Image
    points = prompts["points"]  # Get the list of points

    draw = ImageDraw.Draw(image)
    radius = 5  # Radius of the circle to draw

    # Draw each point on the image
    for point in points:
        x, y = point
        draw.ellipse(
            (x - radius, y - radius, x + radius, y + radius), fill="red", outline="red"
        )

    return image, points


# Define the Gradio interface
demo = gr.Interface(
    fn=draw_points_on_image,  # Function that handles the image and points
    inputs=ImagePrompter(
        show_label=False
    ),  # ImagePrompter for image input and point selection
    outputs=[
        gr.Image(show_label=False),
        gr.Dataframe(label="Points"),
    ],  # Outputs: Image with points and DataFrame of points
    title="Image Point Marker",
    description="Upload an image, click on it, and see the points marked.",
)

# Launch the Gradio app
demo.launch()