Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
import spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
@spaces.GPU(duration=200)
|
| 6 |
def LeYOLO_inference(image, model_id, image_size, conf_threshold, iou_threshold):
|
| 7 |
-
|
|
|
|
| 8 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def app():
|
|
@@ -17,14 +51,12 @@ def app():
|
|
| 17 |
model_id = gr.Dropdown(
|
| 18 |
label="Model",
|
| 19 |
choices=[
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"
|
| 24 |
-
"yolov10l",
|
| 25 |
-
"yolov10x",
|
| 26 |
],
|
| 27 |
-
value="
|
| 28 |
)
|
| 29 |
image_size = gr.Slider(
|
| 30 |
label="Image Size",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
import spaces
|
| 4 |
+
import supervision as sv
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
box_annotator = sv.BoxAnnotator()
|
| 9 |
+
|
| 10 |
+
category_dict = {
|
| 11 |
+
0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
|
| 12 |
+
6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant',
|
| 13 |
+
11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat',
|
| 14 |
+
16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear',
|
| 15 |
+
22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag',
|
| 16 |
+
27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard',
|
| 17 |
+
32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove',
|
| 18 |
+
36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle',
|
| 19 |
+
40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl',
|
| 20 |
+
46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli',
|
| 21 |
+
51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake',
|
| 22 |
+
56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table',
|
| 23 |
+
61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard',
|
| 24 |
+
67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink',
|
| 25 |
+
72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors',
|
| 26 |
+
77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
|
| 27 |
+
}
|
| 28 |
|
| 29 |
@spaces.GPU(duration=200)
|
| 30 |
def LeYOLO_inference(image, model_id, image_size, conf_threshold, iou_threshold):
|
| 31 |
+
model_path = download_models(model_id)
|
| 32 |
+
model = model = YOLO(f"kadirnar/{model_id}")
|
| 33 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
| 34 |
+
detections = sv.Detections.from_ultralytics(results)
|
| 35 |
+
|
| 36 |
+
labels = [
|
| 37 |
+
f"{category_dict[class_id]} {confidence:.2f}"
|
| 38 |
+
for class_id, confidence in zip(detections.class_id, detections.confidence)
|
| 39 |
+
]
|
| 40 |
+
annotated_image = box_annotator.annotate(image, detections=detections, labels=labels)
|
| 41 |
+
|
| 42 |
+
return annotated_image
|
| 43 |
|
| 44 |
|
| 45 |
def app():
|
|
|
|
| 51 |
model_id = gr.Dropdown(
|
| 52 |
label="Model",
|
| 53 |
choices=[
|
| 54 |
+
"LeYOLOSmall",
|
| 55 |
+
"LeYOLONano",
|
| 56 |
+
"LeYOLOMedium",
|
| 57 |
+
"LeYOLOLarge",
|
|
|
|
|
|
|
| 58 |
],
|
| 59 |
+
value="LeYOLOMedium",
|
| 60 |
)
|
| 61 |
image_size = gr.Slider(
|
| 62 |
label="Image Size",
|