Spaces:
Runtime error

File size: 1,004 Bytes
cfb56e5
9f20cee
 
 
 
cfb56e5
 
 
9f20cee
 
 
1441e37
9f20cee
cfb56e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f20cee
cfb56e5
9f20cee
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)