gnarlynerd commited on
Commit
9698467
1 Parent(s): 61becf6

adding demo

Browse files
Files changed (1) hide show
  1. demo.py +70 -0
demo.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[8]:
5
+
6
+
7
+
8
+
9
+
10
+ # In[ ]:
11
+
12
+
13
+ #|export
14
+ from fastai.vision.all import *
15
+ import gradio as gr
16
+
17
+ def is_cat(x): return x[0].isupper()
18
+
19
+
20
+ # In[10]:
21
+
22
+
23
+
24
+
25
+
26
+ # In[11]:
27
+
28
+
29
+ #|export
30
+ learn = load_learner('model.pkl')
31
+
32
+
33
+ # In[12]:
34
+
35
+
36
+
37
+
38
+
39
+ # In[13]:
40
+
41
+
42
+ #|export
43
+ categories = ('Dog', 'Cat')
44
+
45
+ def classify_image(img):
46
+ pred,idx,probs = learn.predict(img)
47
+ return dict(zip(categories, map(float,probs)))
48
+
49
+
50
+ # In[14]:
51
+
52
+
53
+
54
+
55
+
56
+ # In[15]:
57
+
58
+
59
+ #|export
60
+ image = gr.inputs.Image(shape=(192, 192))
61
+ label = gr.outputs.Label()
62
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
63
+
64
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
65
+ intf.launch(inline=False)
66
+
67
+
68
+
69
+
70
+