Muhammad Abdullahi
changed the code
7499d49
raw
history blame
No virus
988 Bytes
import gradio as gr
from fastai.vision.all import *
learner = load_learner('model.pkl')
categories = ('Kentish plover', 'White-faced plover')
def classify_images(img):
pred, index, probs = learner.predict(img)
return dict(zip(categories, map(float, probs)))
# return {learner.dls.vocab[i]: float(probs[i]) for i in range(len(learner.dls.vocab))}
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ['kentish.png', 'white-faced.png']
intf = gr.Interface(fn=classify_images, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)
# intface = gr.Interface(fn=classify_images, inputs=gr.inputs.Image(type='pil'),
# outputs=gr.outputs.Label(num_top_classes=2),
# title="Kentish plover vs White-faced plover Classifier",
# description="Upload an image of either Kentish plover and White-faced plover."
# )
# intface.launch(share=True)