minima / app.py
faishaltm's picture
Update app.py
dc71159
raw
history blame contribute delete
768 Bytes
from fastai import *
from fastai.vision.all import *
import gradio as gr
import pathlib
# def is_cat(x): return x[0].isupper()
# Ensure that the correct Path object is used here based on the OS
# pathlib.PosixPath = pathlib.WindowsPath
# path = Path()
# model_path = str(Path('export.pkl'))
# learn = load_learner(model_path)
learn = load_learner('bear.pkl')
categories = ('black', 'grizzly', 'teddy')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
image = gr.components.Image(type="pil", height=192, width=192)
label = gr.Label()
examples = ['bear.jpg', 'cat.jpg', 'dog.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)