ahmadreza13 commited on
Commit
23bcdd3
1 Parent(s): 211ed33

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLOv10
3
+ import supervision as sv
4
+
5
+
6
+ box_annotator = sv.BoxAnnotator()
7
+ category_dict = {
8
+ 0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
9
+ 6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant',
10
+ 11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat',
11
+ 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear',
12
+ 22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag',
13
+ 27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard',
14
+ 32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove',
15
+ 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle',
16
+ 40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl',
17
+ 46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli',
18
+ 51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake',
19
+ 56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table',
20
+ 61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard',
21
+ 67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink',
22
+ 72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors',
23
+ 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
24
+ }
25
+
26
+ model = YOLOv10("./yolov10n.pt")
27
+ def show_image(img):
28
+
29
+ results = model(source=img, verbose=False)[0]
30
+ detections = sv.Detections.from_ultralytics(results)
31
+
32
+ labels = [
33
+ f"{category_dict[class_id]} {confidence:.2f}"
34
+ for class_id, confidence in zip(detections.class_id, detections.confidence)
35
+ ]
36
+ annotated_image = box_annotator.annotate(img, detections=detections, labels=labels)
37
+
38
+ return annotated_image
39
+
40
+
41
+ app = gr.Interface(
42
+ fn=show_image,
43
+ inputs=gr.Image(label="Input Image Component"), # type= parameter not set. Defaults to numpy.array
44
+ outputs=gr.Image(label="Output Image Component"),
45
+ )
46
+
47
+ app.launch()