File size: 1,169 Bytes
0c03a0b
990e9e8
521a68f
6819837
e560bc6
 
 
1cd93b4
e560bc6
722f1de
eec986c
e560bc6
 
c3239fd
 
 
 
 
 
3711709
04f6df4
3711709
 
6819837
 
 
 
ce10a39
88a8164
6819837
 
521a68f
6819837
 
 
8d7e9fb
88a8164
e685e6c
ce10a39
976b813
6819837
 
 
5a6049a
88a8164
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
import gradio as gr
from fastai.vision.all import *
# import os
# Load a pre-trained image classification model
import pathlib
plt = platform.system()
if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath

root = os.path.dirname(__file__)



def get_label(fname):
    id = int(fname.name[-9:-4])
#     print(id)
    cls = int(labels[id-1])-1
#     print(cls)
    return name(cls)

learn = load_learner("./models/model.pkl")


# Function to make predictions from an image
def classify_image(image):
    # Make a prediction
    # Decode the prediction and get the class name
    name = learn.predict(image)
    return name[0]

# Sample images for user to choose from
sample_images = ["./sample_images/AcuraTLType-S2008.jpg", "./sample_images/AudiR8Coupe2012.jpg","./sample_images/DodgeMagnumWagon2008.jpg"]

iface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(label="Select an image", type="filepath"),
    outputs="text",
    live=False,
    title="Car image classifier",
    description="Upload a car image or select one of the examples below",
    examples=sample_images
)


iface.launch()