File size: 725 Bytes
2b76060
 
 
 
 
 
770c433
2b76060
 
 
 
 
770c433
 
 
2b76060
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from fastai.vision.all import *
import gradio as gr
import os
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"

learn = load_learner('bears.pkl', cpu=True)
learn.model.eval()

def classify_image(img):
    img = PILImage.create(img)
    pred, idx, probs = learn.predict(img)
    results = {label: float(p) for label, p in zip(learn.dls.vocab, probs)}
    results['no bear'] = max(0, 1.0 - max(results.values()))
    return results

image = gr.Image(width=192, height=192, type="pil")
label = gr.Label()
examples = ['gry.jpeg', 'black.jpeg', 'ted.jpeg', 'white3.jpeg']

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