File size: 1,024 Bytes
f91b95e
 
 
 
 
 
 
 
 
59dd53a
f91b95e
 
b9291b9
f91b95e
b9291b9
7634255
f91b95e
7634255
 
f91b95e
7634255
 
 
 
 
 
 
f91b95e
 
 
 
 
b9291b9
f91b95e
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
import cv2
import requests
import os
 
from ultralytics import YOLO

path = ['./data/0068.jpg']

model_path = './best.pt'
model = YOLO(model_path)

def detect_cheerios(image_path):
    # Run inference on the input image
    results = model(image_path)
    image = results[0].plot() 
    
    # # Get the first result (assuming single image input)
    # result = results[0]
    
    # # Draw bounding boxes on the image
    # for box in result.boxes:
    #     x1, y1, x2, y2 = box.xyxy[0]
    #     conf = box.conf[0]
    #     cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2)
    #     cv2.putText(image, f'Apple: {conf:.2f}', (int(x1), int(y1) - 10),
    #                 cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
    
    return image
 
iface = gr.Interface(
    fn=detect_cheerios,
    inputs=gr.components.Image(type="filepath", label="Input Image"),
    outputs=gr.Image(),
    title="Cheerios detector",
    examples=path,
)

# Launch the interface
iface.launch()