File size: 729 Bytes
e601273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d655f9b
e91cfba
e601273
 
 
 
 
 
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
__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)))

image_dir = 'images'
examples = list(map(lambda image_name: f"{image_dir}/{image_name}", os.listdir(image_dir)))

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

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