IAMTFRMZA commited on
Commit
a46d102
·
verified ·
1 Parent(s): b895603

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+
5
+ # Load YOLOv8 model (first time it downloads weights)
6
+ model = YOLO("yolov8n.pt")
7
+
8
+ def check_for_car(image):
9
+ # Run prediction
10
+ results = model.predict(image)
11
+
12
+ # Check for 'car' in detected classes
13
+ for result in results:
14
+ for box in result.boxes:
15
+ cls_id = int(box.cls[0])
16
+ if model.names[cls_id] == 'car':
17
+ return "✅ Car detected!"
18
+ return "❌ No car detected."
19
+
20
+ iface = gr.Interface(
21
+ fn=check_for_car,
22
+ inputs=gr.Image(type="pil", label="Upload an Image"),
23
+ outputs=gr.Textbox(label="Detection Result"),
24
+ title="🚗 Car Detector",
25
+ description="Upload an image to see if a car is present using YOLOv8.",
26
+ )
27
+
28
+ iface.launch()