| from fastai.vision.all import * | |
| import gradio as gr | |
| # def is_cat(x): return x[0].isupper() | |
| # import pathlib | |
| # temp = pathlib.PosixPath | |
| # pathlib.PosixPath = pathlib.WindowsPath | |
| learn = load_learner('export.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) |