File size: 795 Bytes
fe54104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import cv2
from ultralytics import YOLO

# Load a pretrained YOLO model (you can also use "yolov8n.pt" or "yolo11n.pt")
model = YOLO("yolov8n-face.pt")  # You can change to your trained face model

# Function to run detection
def detect_faces(image):
    # Run YOLO detection
    results = model.predict(image, conf=0.4)

    # Draw bounding boxes
    annotated_image = results[0].plot()
    return annotated_image

# Gradio interface
iface = gr.Interface(
    fn=detect_faces,
    inputs=gr.Image(type="numpy", label="Upload or Capture Image"),
    outputs=gr.Image(type="numpy", label="Detected Faces"),
    title="Face Detection App",
    description="Detect faces in an image using YOLO model."
)

if __name__ == "__main__":
    iface.launch()