File size: 459 Bytes
0e2f818
 
 
 
 
 
 
 
 
 
 
 
 
023fc7f
0e2f818
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from fastai.vision.all import *
import gradio as gr

learn = load_learner('model.pkl')

categories = [cat[:-4] for cat in learn.dls.vocab]

def classify_image(img):
    pred, pred_idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

demo = gr.Interface(
    fn=classify_image,
    inputs=[gr.Image(shape=(192,192), source='webcam')],
    outputs=[gr.Label()],
    examples=['male.jpg', 'female.jpg']
)
demo.launch(inline=False)