Spaces:
Runtime error
Runtime error
Download app.py from Nikhil951108/faceclassification: direct link, hf CLI and curl.
- Browser
- Download file 731 Bytes
-
https://huggingface.co/spaces/Nikhil951108/faceclassification/resolve/main/app.py
- Command line
-
hf download hf://spaces/Nikhil951108/faceclassification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Nikhil951108/faceclassification/resolve/main/app.py
731 Bytes
| import numpy as np | |
| import cv2 | |
| import gradio as gr | |
| from PIL import Image | |
| def detect_faces(image): | |
| image_np = np.array(image) | |
| gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY) | |
| face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + | |
| "haarcascade_frontalface_default.xml") | |
| faces = face_cascade.detectMultiScale(gray_image, | |
| scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) | |
| for (x, y, w, h) in faces: | |
| cv2.rectangle(image_np, (x, y), (x+w, y+h), (0, 255, 0), 2) | |
| return image_np | |
| SARWAN@NIELIT CHANDIGARH 8 | |
| iface = gr.Interface( | |
| fn=detect_faces, | |
| inputs="image", | |
| outputs="image", | |
| title="Face Detection", | |
| description="Upload an image, | |
| and the model will detect faces | |
| and draw bounding boxes around | |
| them.", | |
| ) | |
| iface.launch() | |