epilef68's picture
Fix bug with YOLO receiving file_path correctly
b9291b9 verified
raw
history blame
1.02 kB
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()