xiang-wuu commited on
Commit
2d27b0e
·
1 Parent(s): 3054692

gradio app with yolov5 inference with sample images added

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import numpy as np
4
+ import supervision as sv
5
+ from ultralytics import YOLO
6
+
7
+
8
+ def detect(image, weights):
9
+ model = YOLO(weights)
10
+ result = model(image, verbose=False)[0]
11
+ detections = sv.Detections.from_ultralytics(result)
12
+ box_annotator = sv.BoxAnnotator()
13
+ annotated_image = box_annotator.annotate(image.copy(), detections=detections)
14
+
15
+ return annotated_image
16
+
17
+
18
+ if __name__ == '__main__':
19
+ gr.Interface(
20
+ detect, [gr.Image(type="numpy"), gr.Dropdown(choices=["yolov5s", "yolov5s6"])],
21
+ gr.Image(type="numpy"),
22
+ title="Yolov5",
23
+ examples=[["https://media.roboflow.com/notebooks/examples/dog.jpeg", "yolov5s"]],
24
+ description=
25
+ "Gradio based demo for <a href='https://github.com/roboflow/supervision' style='text-decoration: underline' target='_blank'>roboflow/supervision</a>, We write your reusable computer vision tools."
26
+ ).launch()