from fastai import * from fastai.vision.all import * import gradio as gr import skimage learn = load_learner('export.pkl') ## function to use with gradio ## we need this to make prediction on future images labels = learn.dls.vocab ## retrives labels def predict(img): img = PILImage.create(img) # read images pred,pred_idx,probs = learn.predict(img) ### get pred , pred_index and prob for a a given image return {labels[i]: float(probs[i]) for i in range(len(labels))} title = " Car type Classifier" description = "A car classifier trained using the Oxford car dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces." article="
" examples=["2009_bugatti_veyron_grand_sport_10.jpg", "07-x5-bmw.jpg"] interpretation='default' enable_queue=True gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3), examples=examples, title=title, description=description, article=article, enable_queue= enable_queue, interpretation=interpretation ).launch(share=True)