Spaces:
Sleeping
Sleeping
File size: 1,033 Bytes
ca45f71 646a870 ca45f71 3055888 ca45f71 3055888 ca45f71 3055888 ca45f71 3055888 870cbb5 55a3acd 3055888 cf42029 ca45f71 917b961 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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)
|