Spaces:
Sleeping
Sleeping
import gradio as gr | |
#| export (creating a gradio interface) | |
from fastai.vision.all import * | |
import pathlib | |
plt = platform.system() | |
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath | |
learn = load_learner("bear_model.pkl") | |
categories = ('black', 'grizzly', 'teddy') | |
def classify_image(img): | |
pred,idx,probs = learn.predict(img) | |
return dict(zip(categories, map(float, probs))) | |
image = gr.inputs.Image(shape=(192, 192)) | |
label = gr.outputs.Label() | |
# example images | |
examples = ['blackbear.jpg', 'teddybear.jpg', 'grizzlybear.jpg'] | |
# define interface below | |
intf = gr.Interface(fn=classify_image, inputs = image, outputs = label, examples=examples) | |
intf.launch(inline=False) |