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()