laicc-model-app / app.py
Mason Grimshaw
adding debug statements for function
758d3f9
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
# %% auto 0
__all__ = ['path_to_pkl_model', 'learn', 'categories', 'image', 'label', 'intf', 'classify_image']
# %% ../app.ipynb 3
from fastai.vision.all import *
import gradio as gr
path_to_pkl_model = 'model.pkl'
# %% ../app.ipynb 6
learn = load_learner(path_to_pkl_model)
# %% ../app.ipynb 9
categories = learn.dls.vocab # learn.dls.vocab provides the categories from our trained model
new_categories = []
name_map = {"Yucca": "Hupȟéstola",
"Prairie_Turnip": "Timspila",
"Prairie_Turnip_Root": "Timpsila",
"Juniper": "Hanté",
"Poison_Hemlock": "Yažópi-hú",
"Spruce": "wazíȟčaka",
"Flax": "Haȟúntahu",
"Plantain":"Wihúta-hú-iyéčhata",
#"Scarlet_Gaura": "tȟatȟáwabluška",
"Scarlet_Guara": "tȟatȟáwabluška",
"Stone_Seed": "sunkačanka huipiye",
"Juneberry": "wípazutkȟaŋ",
"Wild_Rose_Bush": "uŋžíŋžiŋtka hú",
"Red_Willow": "čhaŋšáša",
"Cow_Parsnip": "pangi tȟáŋka",
"Harebell": "waȟpé tȟó",
"Yarrow": "tȟaópi pȟežúta",
"Silver_Leaf_Scurfpea": "matȟó tȟathíŋpsila",
"Poison_Ivy": "wikȟóška pȟežúta",
"Burr_Oak_Tree": "útahu čháŋ",
"Sochan": "wahpe zizicha sake",
"Sego_Lily": "pšíŋ tȟáŋka",
"Box_Elder_Mushroom": "čhaŋnákpa",
"Box_Elder_Maple_Tree": "čhaŋšúška",
"Pine_Tree": "wazí čháŋ",
"Chokecherry": "čhaŋpȟá",
"Smooth_Brome": "pezhi wasicun",
"Burdock": "waȟpé tȟáŋka",
"Yellow_Sweet_Clover": "waȟpé swúla",
"Goatsbeard": "waȟčá zí iyéčheča",
"Dog_Bane": "napéoilekiyapi",
"Black_Hills_Spruce": "wazíȟčaka",
"Raspberry_Shrub": "tȟakȟáŋhečala hú", }
for category in categories:
if category in name_map.keys():
new_categories.append(name_map[category] + f"_({category})")
else:
new_categories.append(category)
print(category)
categories = new_categories
def classify_image(img):
img = PILImage.create(img).resize((192, 192))
pred,idx,probs = learn.predict(img)
print(pred, idx, probs)
return dict(zip(categories, map(float,probs)))
# %% ../app.ipynb 12
image = gr.Image()
label = gr.Label()
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
intf.launch(inline=False)