File size: 1,012 Bytes
3e33a95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# coding: utf-8

get_ipython().system('pip install nbdev')
get_ipython().system('pip install ipywidgets')

get_ipython().system('pip install notebook2script')

get_ipython().system('pip install -Uqq fastai')
get_ipython().system('pip install gradio')

get_ipython().system('pip install typing_extensions==4.7.1 --upgrade')

#!export
from fastai.vision.all import *
from fastai.vision.widgets import *
import gradio as gr

#!export
categories = ("black","grizzly", "teddy")
def classify_image(img):
    path = Path()
    path.ls(file_exts='.pkl')
    learn_inf = load_learner(path/'modlbear.pkl')
    pred, idx, probs = learn_inf.predict(img)
    return dict(zip(categories, map(float, probs)))


image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ['black_bear.jpeg','grizzly_bear.jpeg', 'teddy_bear.jpeg']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples,  title="Bear Classifier")
intf.launch(inline=False, share=True)