import gradio as gr | |
from PIL import Image, ImageDraw | |
# Define a function that marks the clicked point on the image | |
def mark_point(image, xy): | |
# Convert the Gradio image (which is a numpy array) to a PIL Image | |
img = Image.fromarray(image) | |
# Draw a red circle at the clicked point | |
draw = ImageDraw.Draw(img) | |
radius = 5 | |
x, y = xy | |
draw.ellipse( | |
(x - radius, y - radius, x + radius, y + radius), fill="red", outline="red" | |
) | |
return img | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=mark_point, # The function that marks the point on the image | |
inputs=gr.Image( | |
type="numpy", tool="select" | |
), # Image input with the select tool enabled | |
outputs="image", # The output will be an image with the point marked | |
title="Image Point Marker", | |
description="Upload an image, click on it, and see the point marked.", | |
) | |
# Launch the Gradio app | |
iface.launch() | |