File size: 1,177 Bytes
bf447bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
# AUTOGENERATED! DO NOT EDIT! File to edit: evclassifierapp.ipynb.

# %% auto 0
__all__ = ['learn', 'labels', 'title', 'description', 'interpretation', 'examples', 'enable_queue', 'intf', 'classify_image']

# %% evclassifierapp.ipynb 1
from fastai.vision.all import *

# %% evclassifierapp.ipynb 2
learn = load_learner('export.pkl')

# %% evclassifierapp.ipynb 4
labels = learn.dls.vocab

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

# %% evclassifierapp.ipynb 5
title = "EV Car Classifier"
description = "This model will recognise the EV car in question"
interpretation='default'
examples = ['bmw ix.jpg','merc eqc.jpg','tesla model 3.jpg']
enable_queue=True

# %% evclassifierapp.ipynb 6
import gradio as gr

intf = gr.Interface(fn=classify_image,
             inputs=gr.inputs.Image(shape=(512, 512)),
             outputs=gr.outputs.Label(num_top_classes=3),
             title=title,
             description=description,
             examples=examples,
             interpretation=interpretation,
             enable_queue=enable_queue)
intf.launch()