Spaces:
Sleeping
Sleeping
from fastai.vision.all import * | |
import gradio as gr | |
from pathlib import Path | |
#import pathlib | |
#temp = pathlib.PosixPath | |
#pathlib.PosixPath = pathlib.WindowsPath | |
nut_labels = [ | |
'raw Almonds', | |
'raw Brazil nut', | |
'raw Cashew nut', | |
'raw Chestnut', | |
'raw Ginkgo nut', | |
'raw Hazelnuts', | |
'raw Hickory nut', | |
'raw Maccademia nut', | |
'raw Peanut', | |
'raw Pecans', | |
'raw Pili nut', | |
'raw Pine nut', | |
'raw Pistachios nut', | |
'raw Walnuts' | |
] | |
model = load_learner('nut-recognizer-v14 .pkl') | |
def recognize_image(image): | |
pred, idx, probs = model.predict(image) | |
return dict(zip(nut_labels, map(float, probs))) | |
image = gr.inputs.Image(shape=(192,192)) | |
label = gr.outputs.Label(num_top_classes=5) | |
examples = [ | |
'pistachios.jpeg', | |
'cashew.jpg', | |
'macadamia.jpg', | |
'walnuts.jpg', | |
'chestnuts.jpg', | |
'pili nuts.jpg', | |
'ginkgo nuts.jpg' | |
] | |
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples) | |
iface.launch(inline=False) | |