import gradio as gr from ultralytics import YOLO from collections import Counter import torch import cv2 import torch from PIL import Image # cd to yolo5 modelpath='best.pt' model = torch.hub.load('.', 'custom', path=modelpath, source='local') def yolo(im, size=640): g = (size / max(im.size)) # gain im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize results = model(im) # inference results.render() # updates results.imgs with boxes and labels return Image.fromarray(results.ims[0]) inputs = gr.inputs.Image(type='pil', label="Original Image") outputs = gr.outputs.Image(type="pil", label="Output Image") title = "Deep Ocean Trash Detection" description = "Upload an image or click an example image to use." examples = [['test.jpeg'],['plastic1.jpeg']] demo_app=gr.Interface(yolo, inputs, outputs, title=title, description=description, examples=examples,cache_examples=True, analytics_enabled=False).launch( debug=True,share=True)