Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
|
| 5 |
+
# Load a pretrained YOLO model (you can also use "yolov8n.pt" or "yolo11n.pt")
|
| 6 |
+
model = YOLO("yolov8n-face.pt") # You can change to your trained face model
|
| 7 |
+
|
| 8 |
+
# Function to run detection
|
| 9 |
+
def detect_faces(image):
|
| 10 |
+
# Run YOLO detection
|
| 11 |
+
results = model.predict(image, conf=0.4)
|
| 12 |
+
|
| 13 |
+
# Draw bounding boxes
|
| 14 |
+
annotated_image = results[0].plot()
|
| 15 |
+
return annotated_image
|
| 16 |
+
|
| 17 |
+
# Gradio interface
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=detect_faces,
|
| 20 |
+
inputs=gr.Image(type="numpy", label="Upload or Capture Image"),
|
| 21 |
+
outputs=gr.Image(type="numpy", label="Detected Faces"),
|
| 22 |
+
title="Face Detection App",
|
| 23 |
+
description="Detect faces in an image using YOLO model."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
iface.launch()
|