import cv2 import gradio as gr from ultralytics import YOLO def inference(path:str, threshold:float=0.6): print("trying inference with path", path) if path is None: return None,0 model = YOLO('yolo8n_small.pt') # Caution new API since Ultralytics 8.0.43 outputs = model.predict(source=path, show=False, conf=threshold) # new API with Ultralytics 8.0.43. Accepts 'show', 'classes', 'stream', 'conf' (default is 0.25) image = cv2.imread(path) counter = 0 for output in outputs: # mono item batch conf = output.boxes.conf # the tensor of detection confidences xyxy = output.boxes.xyxy cls = output.boxes.cls # 0 is 'person' and 5 is 'bus' 16 is dog nb=cls.size(dim=0) for i in range(nb): box = xyxy[i] if conf[i]