Spaces:
Runtime error
Runtime error
__all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] | |
import gradio as gr | |
def classify_image(img): | |
from fastai.vision.all import load_learner | |
learn = load_learner('lego-bricks-model.pkl') | |
categories = ( | |
'11214 Bush 3M friction with Cross axle', | |
'18651 Cross Axle 2M with Snap friction', | |
'2357 Brick corner 1x2x2', | |
'3003 Brick 2x2', | |
'3004 Brick 1x2', | |
'3005 Brick 1x1', | |
'3022 Plate 2x2', | |
'3023 Plate 1x2', | |
'3024 Plate 1x1', | |
'3040 Roof Tile 1x2x45deg', | |
'3069 Flat Tile 1x2', | |
'32123 half Bush', | |
'3673 Peg 2M', | |
'3713 Bush for Cross Axle', | |
'3794 Plate 1X2 with 1 Knob', | |
'6632 Technic Lever 3M', | |
) | |
pred,idx,probs = learn.predict(img) | |
return dict(zip(categories, map(float,probs))) | |
image = gr.inputs.Image(shape=(192, 192)) | |
label = gr.outputs.Label() | |
examples = ['0002.png', '201706161606-0002.png', '201706161906-0001.png'] | |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
intf.launch(inline=False) | |