File size: 769 Bytes
120510d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
__all__ = ['learn', 'categories', 'examples', 'image', 'label', 'intf', 'classify_image']

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

# the get_y function
def has_tori_logo_parent(o):
    p = Path(o).parent.name
    return p == 'tori-logo'

learn = load_learner('tori-model.pkl')

categories = ['Something else', 'Tori logo']

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

examples = [
    'images/dog.jpeg', 
    'images/cat.jpeg', 
    'images/face.jpg', 
    'images/profile-avatar.jpeg',
    'images/tori-logo.png'    
]

image = gr.Image()
label = gr.Label()

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