Chierh commited on
Commit
cb7d240
·
1 Parent(s): 98296af

application file added

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ __all__ = ['is_cat', 'learn', 'categories', 'classify_image', 'image', 'label', 'examples', 'intf']
3
+
4
+ from fastai.vision.all import *
5
+ import gradio as gr
6
+
7
+ # learner refers to this function
8
+ def is_cat(x): return x[0].isupper()
9
+
10
+ # the model we trained for cat vs dog classification
11
+ learn = load_learner('model.pkl')
12
+
13
+ # function to be used in gradio interface
14
+ categories = ('Dog', 'Cat')
15
+
16
+ def classify_image(img):
17
+ pred, idx, probs = learn.predict(img)
18
+ return dict(zip(categories, map(float, probs)))
19
+
20
+ # gradio interface
21
+ image = gr.inputs.Image(shape(192,192))
22
+ label = gr.outputs.Label()
23
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
24
+
25
+ intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples=examples)
26
+ intf.launch(inline=False)