File size: 776 Bytes
a46d102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from ultralytics import YOLO
from PIL import Image

# Load YOLOv8 model (first time it downloads weights)
model = YOLO("yolov8n.pt")

def check_for_car(image):
    # Run prediction
    results = model.predict(image)

    # Check for 'car' in detected classes
    for result in results:
        for box in result.boxes:
            cls_id = int(box.cls[0])
            if model.names[cls_id] == 'car':
                return "βœ… Car detected!"
    return "❌ No car detected."

iface = gr.Interface(
    fn=check_for_car,
    inputs=gr.Image(type="pil", label="Upload an Image"),
    outputs=gr.Textbox(label="Detection Result"),
    title="πŸš— Car Detector",
    description="Upload an image to see if a car is present using YOLOv8.",
)

iface.launch()