File size: 1,573 Bytes
aeeccc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec422e0
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../lesson_2.ipynb.

# %% auto 0
import gradio as gr
__all__ = ['learn_inf', 'labels', 'title', 'description', 'article',
           'examples', 'interpretation', 'enable_queue', 'predict']

# %% ../../lesson_2.ipynb 0
import fastai

# %% ../../lesson_2.ipynb 1
import pandas

# %% ../../lesson_2.ipynb 2
from fastai.vision.widgets import *

# %% ../../lesson_2.ipynb 3
from fastai.vision.all import *

# %% ../../lesson_2.ipynb 4
learn_inf = load_learner("./export.pkl")

# %% ../../lesson_2.ipynb 6
labels = learn_inf.dls.vocab

# %% ../../lesson_2.ipynb 7


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


# %% ../../lesson_2.ipynb 8

# %% ../../lesson_2.ipynb 9
title = "Car Classifier"
description = "Upload the image of a car to get its type. The model uses the resnet18 trained on a variety of images of cars."
article = "<p style='text-align: center'><a href='https://github.com/aar2dee2' target='_blank'>Made by aar2dee2</a></p>"
examples = ['car2.jpeg', 'car3.jpeg', 'car4.jpeg',
            'car5.jpg', 'car6.jpg', 'car7.jpg']
interpretation = 'default'
enable_queue = True

# %% ../../lesson_2.ipynb 10
gr.Interface(
    fn=predict,
    inputs=gr.inputs.Image(shape=(512, 512)),
    outputs=gr.outputs.Label(num_top_classes=3),
    title=title,
    description=description,
    article=article,
    examples=examples,
    interpretation=interpretation,
    enable_queue=enable_queue).launch()