amaye15
commited on
Commit
·
a0761cf
1
Parent(s):
83a9ebc
point prompt
Browse files- app.py +30 -48
- requirements.txt +0 -4
app.py
CHANGED
|
@@ -1,52 +1,34 @@
|
|
| 1 |
-
import cv2
|
| 2 |
import gradio as gr
|
| 3 |
-
from
|
| 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 |
-
) # Black border for visibility
|
| 33 |
-
if point[2] == 1:
|
| 34 |
-
cv2.circle(img, (x, y), 2, BLUE, thickness=8) # Blue for class 1
|
| 35 |
-
else:
|
| 36 |
-
cv2.circle(img, (x, y), 2, PINK, thickness=8) # Pink for other classes
|
| 37 |
-
|
| 38 |
-
return img # Return the image with the points marked
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
# Create the Gradio interface with an uploadable image
|
| 42 |
-
demo = gr.Interface(
|
| 43 |
-
process_input, # The function to process the input image and points
|
| 44 |
-
PointPromptableImage(), # Custom input component to get points from the user
|
| 45 |
-
gr.Image(), # Output component to display the processed image
|
| 46 |
-
title="Image Upload and Point Marker",
|
| 47 |
-
description="Upload an image, click on it to mark points, and see the points marked.",
|
| 48 |
)
|
| 49 |
|
| 50 |
# Launch the Gradio app
|
| 51 |
-
|
| 52 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageDraw
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# Define a function that marks the clicked point on the image
|
| 6 |
+
def mark_point(image, x, y):
|
| 7 |
+
# Convert the Gradio image to a PIL Image
|
| 8 |
+
img = Image.fromarray(image)
|
| 9 |
+
|
| 10 |
+
# Draw a red circle at the clicked point
|
| 11 |
+
draw = ImageDraw.Draw(img)
|
| 12 |
+
radius = 5
|
| 13 |
+
draw.ellipse(
|
| 14 |
+
(x - radius, y - radius, x + radius, y + radius), fill="red", outline="red"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
return img
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Create the Gradio interface
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=mark_point, # The function that marks the point on the image
|
| 23 |
+
inputs=[
|
| 24 |
+
gr.Image(type="numpy", interactive=True),
|
| 25 |
+
gr.Number(),
|
| 26 |
+
gr.Number(),
|
| 27 |
+
], # Image input and coordinates
|
| 28 |
+
outputs="image", # The output will be an image with the point marked
|
| 29 |
+
title="Image Point Marker",
|
| 30 |
+
description="Upload an image, click on it, and see the point marked.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
# Launch the Gradio app
|
| 34 |
+
iface.launch()
|
|
|
requirements.txt
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
pillow
|
| 3 |
-
gradio-point-promptable-image
|
| 4 |
-
opencv-python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|