File size: 969 Bytes
953d602
 
 
 
 
 
 
ee38576
 
953d602
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee38576
953d602
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: dog_cat_predicter.ipynb.

# %% auto 0
__all__ = ['learn', 'labels', 'image', 'label', 'examples', 'interface', 'is_cat', 'predict_image']

# %% dog_cat_predicter.ipynb 1
from fastai.vision.all import *
import gradio as gr

# %% dog_cat_predicter.ipynb 3
def is_cat(x): return x[0].isupper() 

learn = load_learner('models/dog_cat_model.pkl')

# %% dog_cat_predicter.ipynb 5
labels = ['Dog', 'Cat']

def predict_image(img):
    #Function to predict input image and return a dictionary with each label and probability (as a float)
    pred,pred_idx,probs = learn.predict(img)
    return dict(zip(labels, map(float, probs)))

# %% dog_cat_predicter.ipynb 7
#Define the Gradio Interface

image = gr.inputs.Image(shape=(224, 224))
label = gr.outputs.Label()
examples = ['dog.jpg', 'cat.jpg', 'hamster.jpg']

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