Spaces:
Runtime error
Runtime error
File size: 634 Bytes
4a93acb af012ac 4a93acb af012ac 4a93acb af012ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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) |