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