from fastai.vision.all import *
import gradio as gr

learn = load_learner('carmodel.pkl')

def predict(img):
    labels = learn.dls.vocab
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}



title = "Car Cat Dog Classifier"
description = "A classifier trained on the Oxford Pets and Stanford Cars dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
gr.Interface(fn=predict, inputs="image", outputs="label",title=title,description=description).launch(share=True)