<jupyter_start><jupyter_text>Achebi's Bear Classifier<jupyter_code># Run this commands at the terminal to install voila if you don't have voila
# pip install voila
# jupyter serverextension enable voila --sys-prefix
from fastai.vision.all import *
from fastai.vision.widgets import *
from ipywidgets import HBox,VBox,widgets,Button,Checkbox,Dropdown,Layout,Box,Output,Label,FileUpload # This is an optional code to fastai.widgets
import voila<jupyter_output><empty_output><jupyter_text>The Achebi's Bear Classifier!You need to know whether you're being chased by a dangerous black or grizzly bear, or a sweet teddy bear, and you need an answer fast? Then you've come to the right place. Take a pic of the potentially vicious killer, and click 'upload' to classify it. (Important: this only handles grizzly bears, black bears, and teddy bears. It will not give a sensible answer for polar bears, a bear market, a bear of a man, or hot dogs.)<jupyter_code>path = Path()
learn_inf = load_learner(path/'export.pkl', cpu=True)
btn_upload = widgets.FileUpload()
out_pl = widgets.Output()
lbl_pred = widgets.Label()
def on_click_classify(change):
    img = PILImage.create(btn_upload.data[-1])
    out_pl = widgets.Output()
    out_pl.clear_output()
    with out_pl:
        display(img.to_thumb(128,128))
    pred,pred_idx,probs = learn_inf.predict(img)
    lbl_pred = widgets.Label()
    lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
    
btn_run = widgets.Button(description='Classify')
btn_run.on_click(on_click_classify) 
#btn_upload.observe(on_data_change, names=['data'])
display(VBox([widgets.Label('Select a Bear to Classify !'), btn_upload, btn_run, out_pl, lbl_pred]))<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup