File size: 1,038 Bytes
582d58c
 
 
 
 
 
 
 
 
 
 
 
 
 
e71e3c6
 
582d58c
 
e71e3c6
582d58c
 
 
 
e71e3c6
582d58c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
# import gradio as gr

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

# iface = gr.Interface(
#     fn = greet, 
#     inputs = "text", 
#     outputs = "text"
# )

# iface.launch(share = True)

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

def is_cat(x):
    return x[0].isupper()

#|export
dog_path = 'aku.jpeg'
cat_path = 'munchkin.jpeg'
dunno_path = 'dunno.jpeg'

model_path = 'model.pkl'
learn = load_learner(model_path)

#|export
categories = ('Dog', 'Cat')

def classify_image(image):
    predict, index, probabilities = learn.predict(image)
    output = dict(zip(categories, map(float, probabilities)))
    return output

image = gr.Image() # image = gr.inputs.Image(shape = (192, 192))
label = gr.Label() # label = gr.Label()
examples = [dog_path, cat_path, dunno_path] # examples = ['aku.jpeg', 'munchkin.jpeg', 'dunno.jpeg']

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