Bear / app.py
JumpyJason's picture
add app
3608bcb
raw
history blame
569 Bytes
from fastai.vision.all import *
from fastai.vision.widgets import *
path = Path()
path.ls(file_exts='.pkl')
import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
learn_inf = load_learner(path/'export.pkl')
labels = learn_inf.dls.vocab
def on_click_classify(img):
img = PILImage.create(img)
pred,pred_idx,probs = learn_inf.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
import gradio as gr
gr.Interface(fn=on_click_classify, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3)).launch(share=True)