File size: 1,065 Bytes
7469cf1
 
d12c3b5
68b3950
7469cf1
 
 
 
 
d9f9882
9c0b93e
393d6df
 
7469cf1
68b3950
90c0628
 
5dfa47d
 
68b3950
7469cf1
68b3950
 
 
 
 
7469cf1
 
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
from fastai.vision.all import *
import gradio as gr
import logging
EXAMPLES_PATH = Path('./examples')

learn = load_learner('watersports.pkl')
categories = learn.dls.vocab

def classify_image(img):
    logging.warning('Watch out!!!')  # will print a message to the console
    print('Classifying: ', img)
    pred,idx,probs = learn.predict(img)
    return( dict(zip(categories, map(float,probs))))

interface_options = {
    "title": "Which Watersport? Compare your guess to the machine inference.",
    "description": "Click an image. Click  Submit. Click Clear. Other images can be dragged directly from a google search. \nNote, the machine classifier relies purely on vision, of the image pixels - no other info used.",
    "examples": [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()],
    "examples_per_page": "100"
}                   

iface = gr.Interface(fn=classify_image, 
            inputs=gr.inputs.Image(shape=(192,192)), 
            outputs=gr.outputs.Label(),
            **interface_options)            

iface.launch(inline=False)