JingsAPI commited on
Commit
1bd3b2c
·
1 Parent(s): 388709a

Initial deployment

Browse files
Files changed (3) hide show
  1. app.py +43 -0
  2. best.pt +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load model
7
+ model = YOLO("best.pt")
8
+
9
+ def detect(image):
10
+ # Run inference
11
+ results = model(image, conf=0.5, iou=0.6)
12
+
13
+ # Get annotated image
14
+ annotated = results[0].plot()
15
+
16
+ # Convert BGR to RGB
17
+ annotated_rgb = annotated[..., ::-1]
18
+
19
+ # Print detections
20
+ detections = []
21
+ for box in results[0].boxes:
22
+ class_name = model.names[int(box.cls)]
23
+ confidence = float(box.conf)
24
+ detections.append(f"{class_name}: {confidence:.2f}")
25
+
26
+ detection_text = "\n".join(detections) if detections else "No objects detected"
27
+
28
+ return Image.fromarray(annotated_rgb), detection_text
29
+
30
+ # Gradio UI
31
+ demo = gr.Interface(
32
+ fn=detect,
33
+ inputs=gr.Image(type="numpy", label="Upload Image"),
34
+ outputs=[
35
+ gr.Image(label="Detection Result"),
36
+ gr.Textbox(label="Detections")
37
+ ],
38
+ title="243263S - Traffic Cone & Cardboard Box Detector",
39
+ description="Upload an image to detect traffic cones and cardboard boxes!",
40
+ examples=[],
41
+ )
42
+
43
+ demo.launch()
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:409a1c01b2d4a3b020e7cdb9b42be928140371bcb7227acca6e38d88dc961845
3
+ size 19178586
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ultralytics
2
+ wandb
3
+ gradio
4
+ pillow