File size: 943 Bytes
171c5a2
 
 
 
 
 
75f3e31
171c5a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: ../bear_detector_using_gradio.ipynb.

# %% auto 0
__all__ = ['path', 'learn_inf', 'image', 'label', 'ui', 'classify_image']

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

# %% ../bear_detector_using_gradio.ipynb 2
# Load the model
path = Path()
learn_inf = load_learner(path/'export.pkl')

# %% ../bear_detector_using_gradio.ipynb 3
# Setup the UI
image = gr.components.Image(shape=(192,192))
label = gr.components.Label()

def classify_image(image):
    pred,pred_idx,probs = learn_inf.predict(image)
    return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'

ui = gr.Interface(
    fn=classify_image,
    inputs=image,
    outputs=label,
    examples=['horse.png', 'bear.png', 'cartoon.png'],
    title='Bear Classifier',
    description='A demo of exposing a model to the world with gradio and huggingfaces')

ui.launch(inline=False)