policedetector / app.py
zachlandes's picture
fastai install via req.txt
f8ead9f
import gradio as gr
from fastai.vision.all import *
path = Path()
path.ls(file_exts='.pkl')
learn = load_learner(path/'model.pkl')
labels = learn.dls.vocab # read labels from Data Loader
def classify_image(img):
pred,pred_idx,probs = learn.predict(img) # use passed image for prediction
return {labels[i]: float(probs[i]) for i in range(len(labels))} # return all results
image = gr.inputs.Image(shape=(224,224))
label = gr.outputs.Label()
examples = ['chp.jpg', 'traffic.jpg', 'traffic2.jpg', 'traffic3.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)