# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="FPtdCTumRZhz"
# ## **Scandinanimal - The scandinavian deer classification app**

# + [markdown] id="t3fSPsHuRkgD"
# Have you ever been to the scandinavian forests and wondered if you are facing a moose, caribou or an elk? Upload a picture and you will find out. Unfortunately this app can not handle the bavarian "Wolpertinger", but it can help you if you are Santa Claus and looking for a new reliable caribou.

# + id="JwI3b58FQ9MU"
from fastai.vision.all import *
from fastai.vision.widgets import *

# + id="b-LYfgMDXyoY"
download_url('https://github.com/pds2021/a5-fino-git/releases/download/1/deer_classifier_seraphin.pkl', 'deer_classifier_seraphin.pkl')
learn_inf = load_learner('deer_classifier_seraphin.pkl', cpu=True)
btn_upload = widgets.FileUpload()
btn_run = widgets.Button(description='Classify')
out_pl = widgets.Output()
lbl_pred = widgets.Label()

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)
VBox([widgets.Label('Select your scandinavian deer!'), 
      btn_upload, btn_run, out_pl, lbl_pred])



StarcoderdataJupyterScriptsDedupFiltered