cv-yolo commited on
Commit
dd65482
·
verified ·
1 Parent(s): ce4f8e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -2,8 +2,6 @@ import gradio as gr
2
  import numpy as np
3
  from PIL import Image
4
  from ultralytics import YOLO
5
- import requests
6
- import os
7
 
8
  model = YOLO('best.pt')
9
 
@@ -30,10 +28,14 @@ def gallery_click_event(images, evt: gr.SelectData):
30
  selected_img = load_image_from_gallery(images, index)
31
  return selected_img
32
 
33
- with gr.Blocks() as demo:
 
 
 
34
  with gr.Row():
35
  with gr.Column():
36
  selected_image = gr.Image(label="Selected Image from Gallery", type="pil")
 
37
 
38
  with gr.Column():
39
  image_gallery = gr.Gallery(label="Image Gallery", elem_id="gallery", type="pil")
@@ -41,18 +43,22 @@ with gr.Blocks() as demo:
41
  with gr.Column():
42
  result_image = gr.Image(label="Result Image", type="pil")
43
 
44
- # Update selected image based on gallery click
45
  image_gallery.select(
46
  fn=gallery_click_event,
47
  inputs=image_gallery,
48
  outputs=selected_image
49
  )
50
 
51
- # Predict and display the result image when the selected image changes
52
  selected_image.change(
53
  fn=predict,
54
  inputs=selected_image,
55
  outputs=result_image
56
  )
57
 
 
 
 
 
 
 
58
  demo.launch()
 
2
  import numpy as np
3
  from PIL import Image
4
  from ultralytics import YOLO
 
 
5
 
6
  model = YOLO('best.pt')
7
 
 
28
  selected_img = load_image_from_gallery(images, index)
29
  return selected_img
30
 
31
+ def clear_image():
32
+ return None
33
+
34
+ with gr.Blocks(css=".container { background-color: white; }") as demo:
35
  with gr.Row():
36
  with gr.Column():
37
  selected_image = gr.Image(label="Selected Image from Gallery", type="pil")
38
+ clear_button = gr.Button("Clear")
39
 
40
  with gr.Column():
41
  image_gallery = gr.Gallery(label="Image Gallery", elem_id="gallery", type="pil")
 
43
  with gr.Column():
44
  result_image = gr.Image(label="Result Image", type="pil")
45
 
 
46
  image_gallery.select(
47
  fn=gallery_click_event,
48
  inputs=image_gallery,
49
  outputs=selected_image
50
  )
51
 
 
52
  selected_image.change(
53
  fn=predict,
54
  inputs=selected_image,
55
  outputs=result_image
56
  )
57
 
58
+ clear_button.click(
59
+ fn=clear_image,
60
+ inputs=None,
61
+ outputs=selected_image
62
+ )
63
+
64
  demo.launch()