amaye15
commited on
Commit
·
9afc623
1
Parent(s):
6491684
show point
Browse files- app.py +24 -7
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,21 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_image_prompter import ImagePrompter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Define the Gradio interface
|
5 |
demo = gr.Interface(
|
6 |
-
fn=
|
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
|
18 |
-
description="Upload an image, click on it, and
|
19 |
)
|
20 |
|
21 |
# Launch the Gradio app
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_image_prompter import ImagePrompter
|
3 |
+
from PIL import Image, ImageDraw
|
4 |
+
|
5 |
+
|
6 |
+
# Function to draw points on the image
|
7 |
+
def draw_points_on_image(prompts):
|
8 |
+
image = Image.fromarray(prompts["image"]) # Convert numpy array to PIL Image
|
9 |
+
points = prompts["points"] # Get the list of points
|
10 |
+
|
11 |
+
draw = ImageDraw.Draw(image)
|
12 |
+
radius = 5 # Radius of the circle to draw
|
13 |
+
|
14 |
+
# Draw each point on the image
|
15 |
+
for point in points:
|
16 |
+
x, y = point
|
17 |
+
draw.ellipse(
|
18 |
+
(x - radius, y - radius, x + radius, y + radius), fill="red", outline="red"
|
19 |
+
)
|
20 |
+
|
21 |
+
return image, points
|
22 |
+
|
23 |
|
24 |
# Define the Gradio interface
|
25 |
demo = gr.Interface(
|
26 |
+
fn=draw_points_on_image, # Function that handles the image and points
|
|
|
|
|
|
|
27 |
inputs=ImagePrompter(
|
28 |
show_label=False
|
29 |
), # ImagePrompter for image input and point selection
|
30 |
outputs=[
|
31 |
gr.Image(show_label=False),
|
32 |
gr.Dataframe(label="Points"),
|
33 |
+
], # Outputs: Image with points and DataFrame of points
|
34 |
+
title="Image Point Marker",
|
35 |
+
description="Upload an image, click on it, and see the points marked.",
|
36 |
)
|
37 |
|
38 |
# Launch the Gradio app
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
gradio
|
2 |
gradio-image-prompter
|
|
|
|
1 |
gradio
|
2 |
gradio-image-prompter
|
3 |
+
Pillow
|