carinimage / app.py
IAMTFRMZA's picture
Create app.py
a46d102 verified
raw
history blame contribute delete
776 Bytes
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()