Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[5]:
|
5 |
+
|
6 |
+
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
def is_cat(x): return x[0].isupper()
|
11 |
+
|
12 |
+
|
13 |
+
# In[6]:
|
14 |
+
|
15 |
+
|
16 |
+
learn = load_learner('petsmodel.pkl')
|
17 |
+
|
18 |
+
|
19 |
+
# In[10]:
|
20 |
+
|
21 |
+
|
22 |
+
cat = ('Dog', 'Cat')
|
23 |
+
|
24 |
+
|
25 |
+
# In[11]:
|
26 |
+
|
27 |
+
|
28 |
+
def classify_image(img):
|
29 |
+
res, idx, prob = learn.predict(img)
|
30 |
+
return dict(zip(cat, map(float, prob)))
|
31 |
+
|
32 |
+
|
33 |
+
# In[14]:
|
34 |
+
|
35 |
+
|
36 |
+
image = gr.inputs.Image(shape=(192, 192))
|
37 |
+
label = gr.outputs.Label()
|
38 |
+
photos = ['dog.jpg', 'cat.jpg']
|
39 |
+
|
40 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=photos)
|
41 |
+
intf.launch(inline=False)
|
42 |
+
|