File size: 768 Bytes
0287de1 204fd70 75c3ea8 204fd70 75c3ea8 3edd48b 18c7112 dc71159 204fd70 |
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 |
from fastai import *
from fastai.vision.all import *
import gradio as gr
import pathlib
# def is_cat(x): return x[0].isupper()
# Ensure that the correct Path object is used here based on the OS
# pathlib.PosixPath = pathlib.WindowsPath
# path = Path()
# model_path = str(Path('export.pkl'))
# learn = load_learner(model_path)
learn = load_learner('bear.pkl')
categories = ('black', 'grizzly', 'teddy')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
image = gr.components.Image(type="pil", height=192, width=192)
label = gr.Label()
examples = ['bear.jpg', 'cat.jpg', 'dog.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False) |