changes
Browse files
app.py
CHANGED
@@ -1,7 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
-
iface.launch()
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# ## Dogs v Cats
|
5 |
+
|
6 |
+
# In[32]:
|
7 |
+
|
8 |
+
|
9 |
+
#/default_exp app
|
10 |
+
|
11 |
+
|
12 |
+
# In[1]:
|
13 |
+
|
14 |
+
|
15 |
+
get_ipython().system('pip install gradio')
|
16 |
+
|
17 |
+
|
18 |
+
# In[2]:
|
19 |
+
|
20 |
+
|
21 |
+
#/export
|
22 |
+
from fastai.vision.all import *
|
23 |
import gradio as gr
|
24 |
|
25 |
+
def is_cat(x): return x[0].isupper()
|
26 |
+
|
27 |
+
|
28 |
+
# In[3]:
|
29 |
+
|
30 |
+
|
31 |
+
im = PILImage.create('dog.jpg')
|
32 |
+
im.thumbnail((192,192))
|
33 |
+
im
|
34 |
+
|
35 |
+
|
36 |
+
# In[5]:
|
37 |
+
|
38 |
+
|
39 |
+
#/export
|
40 |
+
learn = load_learner('model.pkl')
|
41 |
+
|
42 |
+
|
43 |
+
# In[6]:
|
44 |
+
|
45 |
+
|
46 |
+
learn.predict(im)
|
47 |
+
|
48 |
+
|
49 |
+
# In[7]:
|
50 |
+
|
51 |
+
|
52 |
+
#/export
|
53 |
+
categories = ('Dog', 'Cat')
|
54 |
+
|
55 |
+
def classify_image(img):
|
56 |
+
pred,idx,probs = learn.predict(img)
|
57 |
+
return dict(zip(categories, map(float,probs)))
|
58 |
+
|
59 |
+
|
60 |
+
# In[8]:
|
61 |
+
|
62 |
+
|
63 |
+
classify_image(im)
|
64 |
+
|
65 |
+
|
66 |
+
# In[10]:
|
67 |
+
|
68 |
+
|
69 |
+
#/export
|
70 |
+
image = gr.inputs.Image(shape=(192,192))
|
71 |
+
label = gr.outputs.Label()
|
72 |
+
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
|
73 |
+
|
74 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
75 |
+
intf.launch(inline=False)
|
76 |
+
|
77 |
+
|
78 |
+
# In[11]:
|
79 |
+
|
80 |
+
|
81 |
+
m = learn.model
|
82 |
+
|
83 |
+
|
84 |
+
# In[12]:
|
85 |
+
|
86 |
+
|
87 |
+
ps = list(m.parameters())
|
88 |
+
|
89 |
+
|
90 |
+
# In[13]:
|
91 |
+
|
92 |
+
|
93 |
+
ps[1]
|
94 |
+
|
95 |
+
|
96 |
+
# # Exporting
|
97 |
+
|
98 |
+
# In[15]:
|
99 |
+
|
100 |
+
|
101 |
+
get_ipython().system('pip install nbdev')
|
102 |
+
|
103 |
+
|
104 |
+
# In[ ]:
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
# In[34]:
|
111 |
+
|
112 |
+
|
113 |
+
import nbdev
|
114 |
+
#nbdev.export.nb_export('Dogs v Cats.ipynb', 'app')
|
115 |
+
nbdev.export.nb_export('Dogs v Cats.ipynb', './')
|
116 |
+
print('Export successful')
|
117 |
+
|
118 |
+
|
119 |
+
# In[ ]:
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
|
|
|
|