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)