File size: 948 Bytes
371d65a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: ../Loading model.ipynb.

# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']

# %% ../Loading model.ipynb 4
from fastai.vision.all import *

# %% ../Loading model.ipynb 5
import gradio as gr

# %% ../Loading model.ipynb 6
def is_cat(x): return x[0].isupper() 

# %% ../Loading model.ipynb 7
learn = load_learner('model.pkl')

# %% ../Loading model.ipynb 17
categories = ('Is not a cat', 'Is a cat')

def classify_image(img):
    pref,idx,probs = learn.predict(img)
    return dict(zip(categories, map(float,probs)))

# %% ../Loading model.ipynb 24
image = gr.inputs.Image(shape=(196,196))
label = gr.outputs.Label()
examples = ['cat.jpeg', 'dog.jpeg', 'cow.jpeg']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
#inline = false just tells gradio not to display the website here
intf.launch(inline=False)