|
|
|
|
|
|
|
__all__ = ['learn', 'options', 'image', 'label', 'examples', 'intf', 'whichBear', 'classify_img'] |
|
|
|
|
|
from fastai.vision.all import * |
|
import gradio as gr |
|
import pathlib |
|
import platform |
|
|
|
def whichBear(x): return x[0].isBear() |
|
|
|
|
|
|
|
def fix_path(): |
|
if platform.system().lower() != "windows": |
|
pathlib.WindowsPath = pathlib.PosixPath |
|
|
|
|
|
fix_path() |
|
|
|
|
|
learn = load_learner("model.pkl") |
|
|
|
|
|
options = ("grizzly", "black", "teddy") |
|
|
|
def classify_img(img): |
|
pred, idx, probs = learn.predict(img) |
|
return dict(zip(options, map(float, probs))) |
|
|
|
|
|
image = gr.Image() |
|
label = gr.Label() |
|
examples = ["brown_bear.jpg", "grizzly_bear.jpg", "teddy_bear.jpg"] |
|
|
|
intf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples) |
|
intf.launch(inline=False) |
|
|