File size: 1,079 Bytes
9fd0800
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d2046d6
9fd0800
 
 
 
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: Deployment.ipynb.

# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'inf', 'get_y', 'classify_images']

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

def get_y(path):
    return parent_label(path).split(' and ')

# %% Deployment.ipynb 3
learn = load_learner('export.pkl')

# %% Deployment.ipynb 8
categories = learn.dls.vocab
def classify_images(img):
    """classifies images and returns the probabilities on each categories."""
    pred, pred_idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

# %% Deployment.ipynb 10
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
# If you have more or less examples, edit this list.
examples = ['apple.jpg', 'orange.jpg', 'apple and orange.jpg', 
            'pear and orange.jpg', 'apple and pear.jpg', 'apple and pear and orange.jpg',
            'random images.jpg']

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