amaye15 commited on
Commit
85c140a
·
1 Parent(s): 0559e3c

make point

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -1,19 +1,33 @@
1
  import gradio as gr
2
- from PIL import Image
3
 
4
 
5
- # Define a function that takes an image as input and returns it
6
- def display_image(image):
7
- return image # Simply return the uploaded image
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
  # Create the Gradio interface
11
  iface = gr.Interface(
12
- fn=display_image, # The function that handles the image
13
- inputs="image", # Expect an image input from the user
14
- outputs="image", # The output will also be an image
15
- title="Image Upload and Display App",
16
- description="Upload an image and it will be displayed below.",
 
 
 
 
17
  )
18
 
19
  # Launch the Gradio app
 
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