File size: 1,364 Bytes
4a3f47f
 
 
 
 
 
 
 
 
 
 
 
6cc5571
4a3f47f
23fc07b
4a3f47f
 
 
 
 
 
 
 
 
 
 
072c3f1
 
4a3f47f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)