Spaces:
Runtime error
Runtime error
Download app.py from Roopalav/DeepOceanPlastic: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/Roopalav/DeepOceanPlastic/resolve/main/app.py
- Command line
-
hf download hf://spaces/Roopalav/DeepOceanPlastic/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Roopalav/DeepOceanPlastic/resolve/main/app.py
1 kB
| 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) |