File size: 708 Bytes
201bc13
 
 
78f495f
201bc13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a39f01
201bc13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
__all__=['learn','classify_image','categories','examples','intf']

import gradio as gr
from fastai.vision.all import *

#load the learner
learn=load_learner('bear_classifier_myver.pkl')

# define categories
categories=['Black bear','Grizzly bear','Teddy bear']

# define the function to classify images
def classify_image(img):
    pred,idx,probs=learn.predict(img)
    return dict(zip(categories,map(float,probs)))

# example images
examples=['grizzly_bear1.jpg','grizzly_bear2.jpg','black+bear1.jpg','black_bear2.jpg','teddy1.jpg','teddy1.jpg']

# creating the interface
intf=gr.Interface(fn=classify_image,inputs="image",outputs="label",examples=examples,title='Bear Classifier')
intf.launch(inline=False)