BigCats / app.py
Bhaskar Kapri
windowsPath error fix
c841d31
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)