Felipe Mejia
commited on
Commit
·
f91b95e
1
Parent(s):
3ddec75
cheerios detector app initialization
Browse files- app.py +39 -0
- data/0068.jpg +0 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
|
6 |
+
from ultralytics import YOLO
|
7 |
+
|
8 |
+
path = ['./data/0068.jpg']
|
9 |
+
|
10 |
+
model_path = './weights/best.pt'
|
11 |
+
model = YOLO(model_path)
|
12 |
+
|
13 |
+
def detect_cheerios(image):
|
14 |
+
# Run inference on the input image
|
15 |
+
results = model(image)
|
16 |
+
|
17 |
+
# Get the first result (assuming single image input)
|
18 |
+
result = results[0]
|
19 |
+
|
20 |
+
# Draw bounding boxes on the image
|
21 |
+
for box in result.boxes:
|
22 |
+
x1, y1, x2, y2 = box.xyxy[0]
|
23 |
+
conf = box.conf[0]
|
24 |
+
cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2)
|
25 |
+
cv2.putText(image, f'Apple: {conf:.2f}', (int(x1), int(y1) - 10),
|
26 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
27 |
+
|
28 |
+
return image
|
29 |
+
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=detect_cheerios,
|
32 |
+
inputs=gr.Image(type="numpy"),
|
33 |
+
outputs=gr.Image(),
|
34 |
+
title="Cheerios detector",
|
35 |
+
examples=path,
|
36 |
+
)
|
37 |
+
|
38 |
+
# Launch the interface
|
39 |
+
iface.launch()
|
data/0068.jpg
ADDED
requirements.txt
ADDED
Binary file (11.2 kB). View file
|
|