File size: 689 Bytes
54b5e2e
 
 
791e331
 
54b5e2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
791e331
54b5e2e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#| export

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

def is_cat(x): return x[0].isupper() # need this redefinition because the learner uses this function

learn = load_learner('model.pkl')

categories = ('Dog', 'Cat')

# turn the output into a dict with categories and probabilities
def classify_image(img): 
    pred, index, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))
    
# gradio interface
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']

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