anibahug's picture
Update app.py
23fc07b
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 <a href='https://www.kaggle.com/datasets/jutrera/stanford-car-dataset-by-classes-folder'> the Oxford car dataset </a> with fastai. Created as a demo for Gradio and HuggingFace Spaces."
article="<p style='text-align: center'><a href='https://github.com/anibahi' target='_blank'> My github </a></p>"
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)