# AUTOGENERATED! DO NOT EDIT! File to edit: ../fastai_lesson_2_bearsInference_colab.ipynb. | |
# %% auto 0 | |
__all__ = ['learn', 'image', 'label', 'examples', 'intf', 'classify_image'] | |
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 1 | |
#Imports | |
import numpy as np # linear algebra | |
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) | |
#hide | |
#[ -e /content ] | |
#pip install -Uqq fastbook | |
# import fastbook | |
# fastbook.setup_book() | |
#hide | |
# from fastbook import * | |
# from fastai.vision.widgets import * | |
# pip install fastai | |
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 3 | |
from fastai.vision.all import * | |
import gradio as gr | |
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 12 | |
learn = load_learner('/bearClassifier.pkl') | |
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 15 | |
def classify_image(img): | |
pred,idx,probs = learn.predict(img) | |
return dict(zip(categories, map(float,probs))) | |
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 18 | |
#create gradio interface | |
image = gr.inputs.Image(shape=(128,128)) | |
label = gr.outputs.Label() | |
examples = ['grizzlyBearA.jpg', 'blackBearA.jpg', 'teddyBearA.jpg'] | |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples ) | |
intf.launch(inline=False) | |