File size: 1,128 Bytes
7199326
4ad0ed0
7199326
4ad0ed0
39c00e2
7199326
4ad0ed0
 
 
 
 
 
644ed8c
6ebd954
644ed8c
6ebd954
 
644ed8c
 
 
 
 
 
 
 
 
 
 
 
 
4ad0ed0
 
 
7199326
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
import gradio as gr
from fastai.vision.all import *

# Load model
learn = load_learner("model.pkl")

# Inference function
def classify_image(img):
    pred, pred_idx, probs = learn.predict(img)
    return {str(c): float(probs[i]) for i, c in enumerate(learn.dls.vocab)}

# Gradio interface
with gr.Blocks(title="Car body style classifier") as demo:
    gr.Markdown("# Upload a car image to classify its body style!")
    gr.Markdown("Uses `convnext_tiny` architecture and achieves *89.66% accuracy*.")
    gr.Markdown("This project was inspired by first two lectures of the [Practical Deep Learning for Coders](https://course.fast.ai/) course.")
    gr.Markdown("Trained [here](https://colab.research.google.com/drive/1wn4-22c1XopPIhM3uBW2Z6hAEAAHGozM)")

    with gr.Row():
        with gr.Column():
            inp = gr.Image(
                label="Upload a car image",
                type="pil"
            )
            btn = gr.Button("Submit")

        with gr.Column():
            out = gr.Label(num_top_classes=3)

    btn.click(classify_image, inputs=inp, outputs=out)

if __name__ == "__main__":
    demo.launch()