markmc commited on
Commit
b94c453
·
unverified ·
1 Parent(s): 0427fe6

Dog cat classifier example from fast AI course

Browse files
Files changed (3) hide show
  1. app.py +16 -3
  2. dog.jpg +0 -0
  3. model.pkl +3 -0
app.py CHANGED
@@ -1,9 +1,22 @@
1
- import gradio as gr
2
 
 
 
 
 
 
 
3
 
4
- def greet(name):
 
 
5
  return "Hello " + name + "!!"
6
 
7
 
8
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
9
  iface.launch()
 
 
1
 
2
+ from fastai.vision.all import *
3
+ def is_cat(x): return x[0].isupper()
4
+
5
+ learn = load_learner('model.pkl')
6
+
7
+ categories = ('Dog', 'Cat')
8
 
9
+ def classify_image(img):
10
+ pred, idx, probs = learn.predict(img)
11
+ return dict(zip(categories, map(float, probs)))
12
  return "Hello " + name + "!!"
13
 
14
 
15
+ import gradio as gr
16
+
17
+ image = gr.inputs.Image(shape=(192,192))
18
+ label = gr.outputs.Label()
19
+ examples = ['dog.jpg']
20
+
21
+ iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
22
  iface.launch()
dog.jpg ADDED
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:163b6864a3d1f1dce6526e09b7f342a67f32dc5b1b2fb3d996cc16c1894f6f99
3
+ size 47064766