import gradio as gr # from fastai.vision.widgets import * from fastai.vision.all import * # import skimage learn = load_learner('3label.pkl') # Cell # categories = ('Tank', 'No-Tank') labels = learn.dls.vocab def classify_image(img): pred,idx,probs = learn.predict(img) # return dict(zip(categories, map(float,probs))) return {labels[i]: float(probs[i]) for i in range(len(labels))} # Cell # image = gr.inputs.Image(shape=(224, 224)) label = gr.outputs.Label() examples = ['fake_1.jpg','fake_2.jpg','tank_6.jfif','tank_7.jfif','tank_0.jfif', 'tank_1.jpg', 'tank_2.jfif', 'tank_3.jfif', 'tank_4.jfif', 'photo_1.jfif', 'photo_2.jfif', 'photo_3.jfif', 'photo_4.jfif', 'photo_5.jfif', 'photo_6.jfif'] intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) intf.launch(inline=False)