Spaces:
Sleeping
Sleeping
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() | |