Spaces:
Sleeping
Sleeping
JANGALA SAKETH commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,21 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
-
|
| 6 |
-
model = YOLO("ultralytics/yolov8n-face")
|
| 7 |
|
| 8 |
-
def
|
| 9 |
image_np = np.array(image)
|
| 10 |
results = model(image_np)
|
| 11 |
|
| 12 |
-
|
| 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 |
|
|
@@ -20,7 +24,7 @@ def detect_faces(image):
|
|
| 20 |
cx = (xmin + xmax) / 2
|
| 21 |
cy = (ymin + ymax) / 2
|
| 22 |
|
| 23 |
-
|
| 24 |
"cx": float(cx),
|
| 25 |
"cy": float(cy),
|
| 26 |
"confidence": float(conf),
|
|
@@ -32,10 +36,10 @@ def detect_faces(image):
|
|
| 32 |
}
|
| 33 |
})
|
| 34 |
|
| 35 |
-
return
|
| 36 |
|
| 37 |
iface = gr.Interface(
|
| 38 |
-
fn=
|
| 39 |
inputs=gr.Image(type="pil"),
|
| 40 |
outputs="json"
|
| 41 |
)
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
+
model = YOLO("yolov8n.pt")
|
|
|
|
| 6 |
|
| 7 |
+
def detect_persons(image):
|
| 8 |
image_np = np.array(image)
|
| 9 |
results = model(image_np)
|
| 10 |
|
| 11 |
+
persons = []
|
| 12 |
|
| 13 |
for r in results:
|
| 14 |
+
for box, cls, conf in zip(r.boxes.xyxy, r.boxes.cls, r.boxes.conf):
|
| 15 |
+
|
| 16 |
+
# class 0 in COCO = person
|
| 17 |
+
if int(cls) != 0:
|
| 18 |
+
continue
|
| 19 |
+
|
| 20 |
if conf < 0.4:
|
| 21 |
continue
|
| 22 |
|
|
|
|
| 24 |
cx = (xmin + xmax) / 2
|
| 25 |
cy = (ymin + ymax) / 2
|
| 26 |
|
| 27 |
+
persons.append({
|
| 28 |
"cx": float(cx),
|
| 29 |
"cy": float(cy),
|
| 30 |
"confidence": float(conf),
|
|
|
|
| 36 |
}
|
| 37 |
})
|
| 38 |
|
| 39 |
+
return persons
|
| 40 |
|
| 41 |
iface = gr.Interface(
|
| 42 |
+
fn=detect_persons,
|
| 43 |
inputs=gr.Image(type="pil"),
|
| 44 |
outputs="json"
|
| 45 |
)
|