Here, we are to use a model trained elsewhere (on Google Cloud).

Importing the pre-trained model

path = Path('./src')
path.ls(file_exts='.pkl')
(#1) [Path('src/exportBear.pkl')]

Note :use the one cell below if you are on Windows

import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
learn_inf = load_learner(path/'exportBear.pkl')
learn_inf.dls.vocab
['black', 'grizzly', 'teddy']

Initialization

btn_upload = SimpleNamespace(data = ['src/grizzly.jpg'])
img = PILImage.create(btn_upload.data[-1])
lbl_pred = widgets.Label()
lbl_pred.value = "Your prediction here"

Create the button to add an image to classify

btn_upload = widgets.FileUpload()

Create the button "Classify" to run the classification

btn_run = widgets.Button(description='Classify')

Display the added image

out_pl = widgets.Output()
out_pl.clear_output()
with out_pl: display(img.to_thumb(128,128))

Create the function that performs the classification from the model on the image

def on_click_classify(change):
    img = PILImage.create(btn_upload.data[-1])
    out_pl.clear_output()
    with out_pl: display(img.to_thumb(128,128))
    pred,pred_idx,probs = learn_inf.predict(img)
    lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'

btn_run.on_click(on_click_classify)

Create the widget containing all the elements

VBox([widgets.Label('Select your bear!'), 
      btn_upload, btn_run, out_pl, lbl_pred])

Note :use the one cell below if you are on Windows

pathlib.PosixPath = temp

Note: To test my model in real life, I invite you to visit my github and launch this notebook on your own environment.

Picture of Initialization

Picture of classification of a photo