File size: 1,031 Bytes
23379b1
 
 
 
 
 
 
 
0779dda
 
23379b1
 
 
 
9b079cc
 
 
 
23379b1
9b079cc
 
23379b1
 
 
 
 
 
 
 
9b079cc
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
# 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
# Function to handle the path conversion if necessary
def fix_path():
    if platform.system().lower() != "windows":
        pathlib.WindowsPath = pathlib.PosixPath

# Call the function to fix path handling before loading the model
fix_path()

# Load the learner
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)