File size: 813 Bytes
02ee079
 
 
 
 
 
 
7af9a53
02ee079
 
 
 
 
 
 
 
 
 
 
 
 
77ddd05
02ee079
 
 
 
 
 
 
 
 
 
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
#| export
from fastai.vision.all import *
import gradio as gr

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

#| export
learn = load_learner('model.pkl')

#| export
categories = ('Dog', 'Cat')

def classify_images(img):
    #'Is it a car?', 'Is it a car? but as zero or one', 'probabillity of [dog, cat]'
    pred, idx, probs = learn.predict(img)
    #return dictionary
    #zip together the categories and the
                                        #turn probs to float
    return dict(zip(categories, map(float, probs)))


examples = ['dog.jpg', 'cat.jpg', 'catdog.jpg', 'he-s-a-catdog-or-dogcat.jpeg']

intf = gr.Interface(
    fn=classify_images,
    inputs=gr.Image(type="pil", image_mode="RGB", height=192, width=192),
    outputs=gr.Label(),
    examples=examples
)

intf.launch()