car_classifier / app.py
bhushanp's picture
path changes
722f1de
raw
history blame
943 Bytes
import gradio as gr
from fastai.vision.all import *
import os
# Load a pre-trained image classification model
root = os.path.dirname(__file__)
learn = load_learner(os.path.join(root, "models", "model.pth"))
# 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 = [os.path.join(root, sample_images, "AcuraTLType-S2008.jpg"), os.path.join(root, sample_images, "AudiR8Coupe2012.jpg"), os.path.join(root, sample_images, "DodgeMagnumWagon2008.jpg")]
iface = gr.Interface(
fn=classify_image,
inputs=gr.Image(label="Select an image", type="filepath"),
outputs="text",
live=True,
title="Car image classifier",
description="Upload a car image or select one of the examples below",
examples=sample_images
)
iface.launch()