File size: 841 Bytes
79d07a1
 
 
 
 
 
 
f6d6aca
 
79d07a1
 
 
 
 
 
 
 
 
 
 
 
 
f6d6aca
79d07a1
 
 
 
 
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: HUC4Web.ipynb.

# %% auto 0
__all__ = ['plt', 'learner', 'categories', 'image', 'label', 'examples', 'intf', 'classify_img']

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

# %% HUC4Web.ipynb 2
import pathlib
plt = platform.system()
if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath

# %% HUC4Web.ipynb 5
learner = load_learner('./export.pkl')

# %% HUC4Web.ipynb 7
categories = 'happy','unhappy'
def classify_img(img):
    pred,idx,probs = learner.predict(img)
    return dict(zip(categories,map(float,probs)))

# %% HUC4Web.ipynb 9
image = gr.inputs. Image (shape= (192, 192))
label = gr.outputs. Label ()
examples = ['unhappy.jpg','happy.jpg']
intf = gr. Interface(fn=classify_img, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)