Spaces:
Sleeping
Sleeping
File size: 788 Bytes
e94ba5b b634404 6f89cb5 c841d31 b634404 e94ba5b |
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 |
from fastai.vision.all import *
import gradio as gr
import pathlib
@contextmanager
def set_posix_windows():
posix_backup = pathlib.WindowsPath
try:
pathlib.WindowsPath = pathlib.PosixPath
yield
finally:
pathlib.WindowsPath = posix_backup
EXPORT_PATH = pathlib.Path('model.pkl')
with set_posix_windows():
learn = load_learner(EXPORT_PATH)
categories = learn.dls.vocab
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()
examples = ['cheetah.jpg','lion.jpg','tiger.jpg','leopard.jpg','jaguar.jpg']
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label,examples=examples)
iface.launch(inline=False) |