File size: 922 Bytes
24cc4a3
 
 
 
 
 
 
 
b14242f
 
24cc4a3
 
a71e6ad
24cc4a3
 
 
 
 
 
 
 
 
 
 
 
a71e6ad
b14242f
24cc4a3
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
26
27
28
29
# AUTOGENERATED! DO NOT EDIT! File to edit: 02_BearClassifierDeployment.ipynb.

# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']

# %% 02_BearClassifierDeployment.ipynb 4
# importing dependencies
from fastai.vision.all import *
import gradio as gr

# %% 02_BearClassifierDeployment.ipynb 5
# creating inference
learn = load_learner('content/bearClassifier.pkl')

# %% 02_BearClassifierDeployment.ipynb 6
categories = ('Black', 'Grizzly', 'Teddy')

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

# %% 02_BearClassifierDeployment.ipynb 7
# gradio interface Setup
image = gr.Image()
label = gr.Label()
examples = ['content/bear1.jpg', 'content/bear2.jpg', 'content/bear3.jpg', 'content/bear4.jpg']

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