File size: 749 Bytes
bd2e2fd
da8b83a
bd2e2fd
da8b83a
ee87c2d
1185f42
 
 
 
bd2e2fd
da8b83a
 
 
 
 
 
 
42fb412
da8b83a
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from fastai.vision.all import *

# load the trained model
learn = load_learner('model.pkl')

# learn.dls.vocab where dls in the dataloaders from DataBlock
categories = ['ant man', 'black panther', 'black widow', 'captain america', 'captain marvel', 
'doctor strange', 'hulk', 'ironman', 'spiderman', 'thanos', 'thor', 'vision']


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

image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ['ironman.jpg','spiderman.jpg','captain.jpg','blackwidow.jpg','doctor_strange.jpg']

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