File size: 741 Bytes
01e58e1
 
 
 
4722e97
 
01e58e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33a436f
01e58e1
33a436f
d2e935a
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
__all__ = ['learn', 'categories', 'examples', 'interface', 'classify_image']

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

print(gr.__version__)

# %% 02_app.ipynb 2
learn = load_learner('model.pkl')

# %% 02_app.ipynb 4
categories = ('black', 'grizzly', 'teddy')

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

# %% 02_app.ipynb 5
# create a gradio interface

# image = gr.inputs.Image(shape=(192,192))
# label = gr.outputs.Label()
# examples = ['examples/black.jpg', 'examples/grizzly.jpg', 'examples/teddy.jpg']

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