|
import gradio as gr |
|
from gradio_image_prompter import ImagePrompter |
|
from PIL import Image, ImageDraw |
|
|
|
|
|
|
|
def draw_points_on_image(prompts): |
|
image = Image.fromarray(prompts["image"]) |
|
points = prompts["points"] |
|
|
|
draw = ImageDraw.Draw(image) |
|
radius = 5 |
|
|
|
|
|
for point in points: |
|
x, y = point |
|
draw.ellipse( |
|
(x - radius, y - radius, x + radius, y + radius), fill="red", outline="red" |
|
) |
|
|
|
return image, points |
|
|
|
|
|
|
|
demo = gr.Interface( |
|
fn=draw_points_on_image, |
|
inputs=ImagePrompter( |
|
show_label=False |
|
), |
|
outputs=[ |
|
gr.Image(show_label=False), |
|
gr.Dataframe(label="Points"), |
|
], |
|
title="Image Point Marker", |
|
description="Upload an image, click on it, and see the points marked.", |
|
) |
|
|
|
|
|
demo.launch() |
|
|