Ubuntu
Replaced a fastbook reference with a fastai reference to get the load_learner function
75f3e31
# 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) | |