File size: 1,123 Bytes
23379b1
 
 
 
 
 
 
 
0779dda
 
23379b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
# 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
import pathlib
import platform


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

# %% app.ipynb 4
original_posix_path = pathlib.PosixPath

# Replace PosixPath with WindowsPath for loading the model if on a POSIX system
if platform.system().lower() != "windows":
    pathlib.PosixPath = pathlib.WindowsPath

# Load the learner
learn = load_learner("model.pkl")

# Restore the original PosixPath class
if platform.system().lower() != "windows":
    pathlib.PosixPath = original_posix_path


# %% 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)