Coddieharsh commited on
Commit
c78041b
·
verified ·
1 Parent(s): bf62192

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ import gradio as gr
3
+
4
+
5
+ def is_cat(x):
6
+ return x[0].isupper()
7
+
8
+
9
+ img = PILImage.create('dog.jpg')
10
+ img.thumbnail((192, 192))
11
+ img
12
+
13
+
14
+
15
+ learn = load_learner('model.pkl')
16
+
17
+ learn.predict(img)
18
+
19
+
20
+ categories = ('Dog', 'Cat')
21
+
22
+ def classify_image(img):
23
+ pred, idx, probs = learn.predict(img)
24
+ return dict(zip(categories, map(float, probs)))
25
+
26
+ classify_image(img)
27
+
28
+
29
+ image = gr.Image(height=192, width=192)
30
+ label = gr.Label()
31
+ examples = ['dog.jpg', 'cat.jpg', 'rabbit.jpg']
32
+
33
+ intf = gr.Interface(fn= classify_image, inputs = image, outputs = label, examples = examples)
34
+ intf.launch(inline = False, share = True)