Sriram Elango commited on
Commit
ecb645e
1 Parent(s): 04b5ef7

Add application file

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. packages.txt +1 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import torch
4
+ from PIL import Image
5
+
6
+
7
+ #subprocess.run(["mv","content/custom_data.yaml","./yolov5/data"])
8
+
9
+
10
+ def load_model():
11
+ '''
12
+ Loading hub model & setting the preferences for the model
13
+ '''
14
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='Content/cnn.pt')
15
+ model.conf = 0.38
16
+ model.dnn=True
17
+ model.agnostic=True
18
+ return model
19
+
20
+ model=load_model()
21
+ #, force_reload=True
22
+ def detect(inp):
23
+ #g = (size / max(inp.size)) #gain
24
+ #im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
25
+ results = model(inp,size=640) # inference
26
+ print(results)
27
+ results.render() # updates results.imgs with boxes and labels
28
+ return Image.fromarray(results.imgs[0])
29
+
30
+
31
+ inp = gr.inputs.Image(type="pil", label="Original Image")
32
+ output = gr.outputs.Image(type="pil", label="Output Image")
33
+
34
+
35
+ io=gr.Interface(fn=detect, inputs=inp, outputs=output, title='Mosquito Habitat Identification',theme='peach')
36
+ io.launch(debug=True,share=False)
37
+
38
+ #examples=['Content/4.jpg','Content/10.jpg','Content/18.jpg']
39
+
40
+
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ libgl1-mesa-glx