File size: 578 Bytes
f2d0244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# coding: utf-8

# In[5]:


from fastai.vision.all import *
import gradio as gr

def is_cat(x): return x[0].isupper() 


# In[6]:


learn = load_learner('petsmodel.pkl')


# In[10]:


cat = ('Dog', 'Cat')


# In[11]:


def classify_image(img):
    res, idx, prob = learn.predict(img)
    return dict(zip(cat, map(float, prob)))


# In[14]:


image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
photos = ['dog.jpg', 'cat.jpg']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=photos)
intf.launch(inline=False)