File size: 728 Bytes
9b4a5ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb6b70b
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
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_gradio_model.ipynb.

# %% auto 0
__all__ = ['learn', 'classify_image']

# %% ../nbs/02_gradio_model.ipynb 2
from fastai.vision.all import *
import gradio as gr

# %% ../nbs/02_gradio_model.ipynb 3
learn = load_learner('star-wars-character-classifier.pkl')

# %% ../nbs/02_gradio_model.ipynb 4
def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(learn.dls.vocab.items, map(float, probs)))

# %% ../nbs/02_gradio_model.ipynb 8
gr.Interface(
    classify_image,
    inputs=gr.inputs.Image(label="Star Wars character", type="filepath"),
    outputs=gr.outputs.Label(num_top_classes=3),
    title="Which Star Wars Character It Is?",
).launch()