File size: 781 Bytes
e77ba73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

def detect_faces(image):

    from huggingface_hub import hf_hub_download
    from ultralytics import YOLO
    from supervision import Detections
    import cv2
    
    model_path = hf_hub_download(repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt")
    model = YOLO(model_path)

    output = model(image)
    results = Detections.from_ultralytics(output[0])

    for i in results:
        im = cv2.rectangle(image, (int(i[0][0]),int(i[0][1])), (int(i[0][2]),int(i[0][3])), (0,0,255), 2)
    
    return im

interface = gr.Interface(
    fn=detect_faces,
    inputs="image",
    outputs="image",
    title="Face Detection with Haar Cascade",
    description="Upload an image, and the model will detect faces and draw bounding boxes around them.",
)
interface.launch()