spreaticsjcastle commited on
Commit
c1ba02e
1 Parent(s): 95e3fe3

add Annotator

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  # load libraries
3
  from huggingface_hub import hf_hub_download
4
  from ultralytics import YOLO
5
- from supervision import Detections
6
  from PIL import Image
7
 
8
  # download model
@@ -19,13 +19,15 @@ import gradio as gr
19
 
20
  def sepia(input_img):
21
  output = model(input_img)
22
- results = Detections.from_ultralytics(output[0])
23
- arr_int = results.xyxy.astype(int)
24
 
25
- for x, y, x2, y2 in arr_int:
26
- cv2.rectangle(input_img, (x, y), (x2, y2), (0, 255, 0), 2)
 
 
 
27
 
28
- return input_img
29
 
30
  demo = gr.Interface(sepia, gr.Image(), "image")
31
  if __name__ == "__main__":
 
2
  # load libraries
3
  from huggingface_hub import hf_hub_download
4
  from ultralytics import YOLO
5
+ import supervision as sv
6
  from PIL import Image
7
 
8
  # download model
 
19
 
20
  def sepia(input_img):
21
  output = model(input_img)
22
+ results = sv.Detections.from_ultralytics(output[0])
 
23
 
24
+ bounding_box_annotator = sv.BoundingBoxAnnotator()
25
+ annotated_frame = bounding_box_annotator.annotate(
26
+ scene = input_img.copy(),
27
+ detections = results
28
+ )
29
 
30
+ return annotated_frame
31
 
32
  demo = gr.Interface(sepia, gr.Image(), "image")
33
  if __name__ == "__main__":