File size: 899 Bytes
2f59b4e
 
 
 
 
 
 
 
 
 
 
7d72877
 
2f59b4e
 
 
 
 
 
ec5b36c
2f59b4e
 
 
 
7d72877
2f59b4e
09e3cc0
 
 
 
7555b10
92e2484
2f59b4e
 
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
# import gradio as gr

# def greet(name):
#     return "Hello " + name + "!!"

# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# demo.launch()
__all__ = ['label_func', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']

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

def label_func(x):
    return "dog" if x[0].islower() else "cat"
# Cell
learn = load_learner('model.pkl')

# Cell
categories = ('Cat', 'Dog')

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

# Cell
# image = gr.inputs.Image(shape=(192, 192))
image = gr.Image(height=192, width=192)
label = gr.Label()
# label = gr.outputs.Label()
examples = ['dog1.jpeg', 'dog2.jpeg', 'dog3.jpeg','cat.jpg']

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