File size: 628 Bytes
f529e19
84ca1d1
 
 
f529e19
 
 
 
 
 
 
34dd8e2
f529e19
 
 
 
 
 
cbb082e
f529e19
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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.1:
        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.jfif', 'cat.jfif', 'bird.jfif', 'koala.jfif']

intf = gr.Interface(fn=predict_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)