File size: 767 Bytes
28a2d92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.

# %% auto 0
__all__ = ['learn', 'options', 'image', 'label', 'examples', 'intf', 'whichBear', 'classify_img']

# %% app.ipynb 2
from fastai.vision.all import *
import gradio as gr


def whichBear(x): return x[0].isBear()

# %% app.ipynb 4
learn = load_learner('model.pkl')


# %% app.ipynb 6
options = ("grizzly", "black", "teddy")

def classify_img(img):
    pred,idx,probs = learn.predict(img)
    return dict(zip(options, map(float, probs)))

# %% app.ipynb 8
image = gr.Image()
label = gr.Label()
examples = ["brown_bear.jpg", "grizzly_bear.jpg", "teddy_bear.jpg"]

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