import gradio as gr from transformers import pipeline # Load model once at startup (downloaded and cached on first run) pipe = pipeline( "image-classification", model="therealcyberlord/stanford-car-vit-patch16", top_k=5, ) def classify_car(image): if image is None: return {} results = pipe(image) return {r["label"]: float(r["score"]) for r in results} demo = gr.Interface( fn=classify_car, inputs=gr.Image(type="pil", label="Upload a car photo"), outputs=gr.Label(num_top_classes=5, label="Top 5 Predictions"), title="🚗 Car Model Classifier", description=( "Upload a photo of a car to identify its **make, model, and year**.\n\n" "Powered by a **Vision Transformer (ViT)** fine-tuned on the " "[Stanford Cars dataset](https://ai.stanford.edu/~jkrause/cars/car_dataset.html) " "— 196 categories covering car make, model, and year (2002–2012)." ), theme=gr.themes.Soft(), ) demo.launch()