sharyash1101 commited on
Commit
eb6d647
1 Parent(s): eab46de

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from gradio import components
4
+ from PIL import Image
5
+ import os
6
+
7
+ model = None
8
+
9
+ def object_detection(im):
10
+ global model
11
+ if model is None:
12
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True)
13
+ results = model(im)
14
+ results.render()
15
+ return Image.fromarray(results.ims[0])
16
+
17
+ image = components.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Imagem")
18
+ outputs = components.Image(type="pil", label="Output Image")
19
+
20
+ iface = gr.Interface(
21
+ fn=object_detection,
22
+ inputs=image,
23
+ outputs=outputs,
24
+ title='Garbage Detection',
25
+ description='A simple demo app for an object detection model to detect garbage in natural and urban environments.',
26
+ examples=sorted([f'examples/{filename}' for filename in os.listdir('examples')]),
27
+ )
28
+ iface.launch(debug=True)