File size: 704 Bytes
62d3088
 
 
b9c36cc
 
62d3088
 
 
 
 
 
 
 
 
 
b9c36cc
62d3088
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
__all__ = ['is_cat', 'learn', 'classify_image', 'categoreies', 'image', 'label', 'examples', 'intf']

from fastai.vision import *
import gradio as gr

def is_cat(x): return x[0].obj == 'cat'

learn = load_learner('model.pkl')

categories = ('Dog', 'Cat')

def classify_image(img):
    pred_class, pred_idx, outputs = learn.predict(img)
    return dict(zip(categories, map(float,probs)))
    # return {'label': str(pred_class), 'confidence': float(outputs[pred_idx])}

image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label(num_top_classes=2)
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
intf = gr.Interface(classify_image, image, label, capture_session=True, examples=examples)
intf.launch()