what_is_it / app.py
Kryko7
finished app.py
f529e19
raw
history blame
624 Bytes
from fastai.vision.all import *
import gradio as gr
learn = load_learner('model.pkl')
categories = {'Dog', 'Cat', 'Bird', 'Koala'}
def predict_image(img):
pred, pred_idx, probs = learn.predict(img)
probs_float = probs[0].item()
if probs_float > 0.5:
return dict(zip(categories, map(float, probs)))
else:
return "Not a dog, cat, bird, or koala"
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
examples = ['dog.jpg', 'cat.jpg', 'bird.jpg', 'koala.jpg']
intf = gr.Interface(fn=predict_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)