|
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): |
|
|
|
results = model(image) |
|
|
|
|
|
result = results[0] |
|
|
|
|
|
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.Image(type="numpy"), |
|
outputs=gr.Image(), |
|
title="Cheerios detector", |
|
examples=path, |
|
) |
|
|
|
|
|
iface.launch() |