Bricks / app.py
NicolasvonRotz's picture
new model
c594360
__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('bricks-model.pkl')
categories = ( 'Brick_11103', 'Brick_112', 'Brick_11262', 'Brick_11833', 'Brick_149', 'Brick_15265', 'Brick_15400', 'Brick_18946', 'Brick_18973', 'Brick_22472', 'Brick_2357', 'Brick_242021', 'Brick_2432', 'Brick_24581', 'Brick_2467', 'Brick_25126', 'Brick_2536', 'Brick_25561', 'Brick_26021', 'Brick_2610', 'Brick_2696', 'Brick_2737', 'Brick_2804', 'Brick_2807', 'Brick_29124', 'Brick_3002', 'Brick_3003', 'Brick_3004', 'Brick_3010', 'Brick_30145', 'Brick_30152', 'Brick_30250', 'Brick_30277', 'Brick_30284', 'Brick_30303', 'Brick_3033', 'Brick_30409', 'Brick_30505', 'Brick_3065', 'Brick_3070', 'Brick_32065', 'Brick_32138', 'Brick_32324', 'Brick_32373', 'Brick_32555', 'Brick_33048', 'Brick_3460', 'Brick_35565', 'Brick_3828', 'Brick_3844', 'Brick_389', 'Brick_3898', 'Brick_40341', 'Brick_41667', 'Brick_4211622', 'Brick_4247', 'Brick_42603', 'Brick_4336', 'Brick_43802', 'Brick_44137', 'Brick_4582471', 'Brick_4599', 'Brick_46225', 'Brick_47994', 'Brick_50304', 'Brick_55704', 'Brick_56220', 'Brick_58120', 'Brick_60621', 'Brick_60657', 'Brick_6075', 'Brick_61506', 'Brick_6190', 'Brick_61905', 'Brick_6214', 'Brick_6223', 'Brick_62622', 'Brick_630', 'Brick_63869', 'Brick_64681', 'Brick_6517', 'Brick_67704', 'Brick_6942', 'Brick_702', 'Brick_72', 'Brick_727', 'Brick_74040', 'Brick_744', 'Brick_74880', 'Brick_76270', 'Brick_76607', 'Brick_80298', 'Brick_88326', 'Brick_89650', 'Brick_90616', 'Brick_9244', 'Brick_9352', 'Brick_94638', 'Brick_97782', 'Brick_98286', 'Brick_99013' )
pred,idx,probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
image = gr.inputs.Image(shape=(256, 256))
label = gr.outputs.Label()
examples = []
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)