Spaces:
Runtime error
Runtime error
gradio component for image detection added
Browse files- detect_utils.py +41 -0
detect_utils.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ultralytics import YOLO
|
3 |
+
import os
|
4 |
+
import supervision as sv
|
5 |
+
|
6 |
+
os.system("wget https://media.roboflow.com/notebooks/examples/dog.jpeg")
|
7 |
+
os.system("wget https://media.roboflow.com/notebooks/examples/dog-2.jpeg")
|
8 |
+
|
9 |
+
|
10 |
+
def detect(image, weights, slider_val):
|
11 |
+
model = YOLO(weights + '.pt')
|
12 |
+
result = model(image, verbose=False)[0]
|
13 |
+
detections = sv.Detections.from_ultralytics(result)
|
14 |
+
box_annotator = sv.BoxAnnotator()
|
15 |
+
annotated_image = box_annotator.annotate(
|
16 |
+
image.copy(), detections=detections)
|
17 |
+
return annotated_image
|
18 |
+
|
19 |
+
|
20 |
+
inputs_thresh = [
|
21 |
+
gr.inputs.Image(type="numpy", label="Input Image"),
|
22 |
+
gr.inputs.Radio(label="Detection Methods",
|
23 |
+
choices=[
|
24 |
+
"yolov5s", "yolov8s"
|
25 |
+
]),
|
26 |
+
gr.components.Slider(label="Class Probability Value",
|
27 |
+
value=10, minimum=1, maximum=100, step=1),
|
28 |
+
]
|
29 |
+
|
30 |
+
outputs_thresh = [
|
31 |
+
gr.outputs.Image(type="numpy", label="Output Image")
|
32 |
+
]
|
33 |
+
|
34 |
+
detect_tab = gr.Interface(
|
35 |
+
detect,
|
36 |
+
inputs=inputs_thresh,
|
37 |
+
outputs=outputs_thresh,
|
38 |
+
title="supervision",
|
39 |
+
examples=[["dog.jpeg", "yolov5s"], ["dog-2.jpeg", "yolov8s"]],
|
40 |
+
description="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."
|
41 |
+
)
|