File size: 1,490 Bytes
d1a7d88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb24336
 
 
 
 
d1a7d88
 
 
 
cb24336
 
 
 
 
 
 
 
 
edc13f6
 
 
 
 
 
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
# credit: https://huggingface.co/spaces/jph00/testing/tree/main
# AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).

__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']

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

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

# Cell
learn = load_learner('model.pkl')

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

def classify_image(img):
    pred,idx,probs = learn.predict(img)
    if probs[0]>probs[1]:
        pred_class = 'This is Dog'
    else:
        pred_class = 'This is Cat'
    return pred_class, dict(zip(categories, map(float,probs)))

# Cell
image = gr.inputs.Image(shape=(192, 192))

set_label = gr.outputs.Textbox(label="Predicted Class")

set_prob = gr.outputs.Label(num_top_classes=2, label="Predicted Probability Per Class")
examples = ['test1.jpg', 'test2.jpg', 'test3.jpeg', 'test4.jpeg', 'test5.jpeg', 'test6.jpeg', 'test7.jpeg', 'test8.jpeg', 'test9.jpeg', 'test10.jpeg']

intf = gr.Interface(fn=classify_image, 
                    inputs=image, 
                    outputs=[set_label, set_prob], 
                    examples_per_page = 2, 
                    examples=examples,
                    title="CSCI4750/5750 Demo 2: Pet classification", 
                         description= "Click examples below for a quick demo",
                         theme = 'huggingface',
                         layout = 'vertical')
intf.launch(inline=False,debug=True)