| import fastbook |
| fastbook.setup_book() |
|
|
| from PIL import Image |
| import requests |
| import gradio as gr |
|
|
| from fastbook import * |
| from fastai.vision.widgets import * |
|
|
| path = Path() |
| path.ls(file_exts='.pkl') |
|
|
| learn_inf = load_learner(path/'export.pkl') |
|
|
| categories = ('grizzly', 'black', 'teddy') |
|
|
| def classify_image(img): |
| pred,idx,probs = learn_inf.predict(img) |
| return dict(zip(categories, map(float,probs))) |
|
|
| image = gr.inputs.Image(shape=(192,192)) |
| label = gr.outputs.Label() |
| |
|
|
| intf = gr.Interface(fn = classify_image, inputs=image, outputs=label) |
| intf.launch(inline=False) |