Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,8 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
model = YOLO("yolov8n-face
|
| 7 |
|
| 8 |
def detect_faces(image):
|
| 9 |
image_np = np.array(image)
|
|
@@ -12,15 +12,18 @@ def detect_faces(image):
|
|
| 12 |
faces = []
|
| 13 |
|
| 14 |
for r in results:
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
cx = (xmin + xmax) / 2
|
| 19 |
cy = (ymin + ymax) / 2
|
| 20 |
|
| 21 |
faces.append({
|
| 22 |
"cx": float(cx),
|
| 23 |
"cy": float(cy),
|
|
|
|
| 24 |
"box": {
|
| 25 |
"xmin": float(xmin),
|
| 26 |
"ymin": float(ymin),
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
+
# Load face model from HF hub
|
| 6 |
+
model = YOLO("ultralytics/yolov8n-face")
|
| 7 |
|
| 8 |
def detect_faces(image):
|
| 9 |
image_np = np.array(image)
|
|
|
|
| 12 |
faces = []
|
| 13 |
|
| 14 |
for r in results:
|
| 15 |
+
for box, conf in zip(r.boxes.xyxy, r.boxes.conf):
|
| 16 |
+
if conf < 0.4:
|
| 17 |
+
continue
|
| 18 |
|
| 19 |
+
xmin, ymin, xmax, ymax = box.cpu().numpy()
|
| 20 |
cx = (xmin + xmax) / 2
|
| 21 |
cy = (ymin + ymax) / 2
|
| 22 |
|
| 23 |
faces.append({
|
| 24 |
"cx": float(cx),
|
| 25 |
"cy": float(cy),
|
| 26 |
+
"confidence": float(conf),
|
| 27 |
"box": {
|
| 28 |
"xmin": float(xmin),
|
| 29 |
"ymin": float(ymin),
|