import gradio as gr import PIL.Image as Image from ultralytics import YOLO model = None def predict_image(img): """Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds.""" model = YOLO("best.pt") # model.predict(source=img, save=True) results = model.predict( source=img, conf=0.25, iou=0.25, show_labels=True, show_conf=True, imgsz=640, ) # results = model(img) for r in results: im_array = r.plot() im = Image.fromarray(im_array[..., ::-1]) return im # return results[0].show() demo = gr.Interface( fn=predict_image, inputs=gr.Image(type="pil", label="Upload Image"), outputs=gr.Image(type="pil", label="Result"), # outputs="image", title="Burks YOLO Coin Detector 🚀", description="Upload your image, stupid.", ) demo.launch(share=True)