Spaces:
Runtime error
Runtime error
File size: 899 Bytes
6d89902 e3c4d00 6d89902 | 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 27 28 29 30 31 32 33 34 35 36 37 38 39 | import platform
import pathlib
plt = platform.system()
if plt == 'Linux':
pathlib.WindowsPath = pathlib.PosixPath
import gradio as gr
from fastai.vision.all import *
from PIL import Image
# Load your trained/saved model
learn = load_learner('model.pkl')
def classify_bear(image):
# convert PIL image to fastai image object
img = PILImage.create(image)
# get predictions
pred, idx, probs = learn.predict(img)
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
example_images = [
'images/black.jpg',
'images/teddy.jpg',
'images/grizzly.jpg',
'images/black2.jpg',
'images/grizzly2.jpg'
]
iface = gr.Interface(
fn=classify_bear,
inputs=gr.Image(type='pil'),
outputs=gr.Label(num_top_classes=3),
examples=example_images,
description="Classify bear images as grizzly, black or teddy:"
)
iface.launch() |