File size: 668 Bytes
6dbdc0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47fe1a3
 
6dbdc0a
 
 
47fe1a3
6dbdc0a
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: ../01.ipynb.

# %% auto 0
__all__ = ['learner', 'labels', 'image', 'predict']

# %% ../01.ipynb 3
from fastai.vision.all import *

# %% ../01.ipynb 4
learner = load_learner('model.pkl')

# %% ../01.ipynb 5
labels = learner.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learner.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

# %% ../01.ipynb 7
import gradio as gr

# %% ../01.ipynb 8
image = gr.inputs.Image(shape=(512, 512))
labels = gr.outputs.Label(num_top_classes=3)

gr.Interface(fn=predict, inputs=image, outputs=labels)
gr.launch(inline=False)