Spaces:
Sleeping
Sleeping
Commit ·
66cf9d4
1
Parent(s): cd968e2
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,17 +7,32 @@ import gradio as gr
|
|
| 7 |
# model = Yolov4(weight_path="best.pt", class_name_path='coco_classes.txt')
|
| 8 |
|
| 9 |
|
| 10 |
-
from ultralytics import YOLO
|
| 11 |
|
| 12 |
# Load a model
|
| 13 |
-
model = YOLO("best.pt") # load a custom model
|
| 14 |
|
| 15 |
# Predict with the model
|
| 16 |
# results = model("image.jpg", save = True) # predict on an image
|
| 17 |
|
|
|
|
| 18 |
|
| 19 |
-
def
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
#print(np.shape(img))
|
| 22 |
results = model.predict(img) # predict on an image
|
| 23 |
try:
|
|
@@ -31,9 +46,11 @@ def gradio_wrapper(img):
|
|
| 31 |
return cv2.putText(img, text,(00, 185), cv2.FONT_HERSHEY_SIMPLEX, 1,
|
| 32 |
(0, 0, 255), 2, cv2.LINE_AA, False)
|
| 33 |
# return results
|
|
|
|
|
|
|
| 34 |
|
| 35 |
demo = gr.Interface(
|
| 36 |
-
|
| 37 |
#gr.Image(source="webcam", streaming=True, flip=True),
|
| 38 |
gr.Image(source="webcam", streaming=True),
|
| 39 |
"image",
|
|
|
|
| 7 |
# model = Yolov4(weight_path="best.pt", class_name_path='coco_classes.txt')
|
| 8 |
|
| 9 |
|
| 10 |
+
# from ultralytics import YOLO
|
| 11 |
|
| 12 |
# Load a model
|
| 13 |
+
# model = YOLO("best.pt") # load a custom model
|
| 14 |
|
| 15 |
# Predict with the model
|
| 16 |
# results = model("image.jpg", save = True) # predict on an image
|
| 17 |
|
| 18 |
+
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
| 19 |
|
| 20 |
+
def detect_faces(frame):
|
| 21 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
| 22 |
+
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
| 23 |
+
print(f"Detected {len(faces)} faces")
|
| 24 |
+
return len(faces)
|
| 25 |
+
|
| 26 |
+
def detect_faces_in_video():
|
| 27 |
+
success, frame = camera.read()
|
| 28 |
+
if success:
|
| 29 |
+
num_faces = detect_faces(frame)
|
| 30 |
+
return int(num_faces)
|
| 31 |
+
else:
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
"""def gradio_wrapper(img):
|
| 35 |
+
global face_cascade
|
| 36 |
#print(np.shape(img))
|
| 37 |
results = model.predict(img) # predict on an image
|
| 38 |
try:
|
|
|
|
| 46 |
return cv2.putText(img, text,(00, 185), cv2.FONT_HERSHEY_SIMPLEX, 1,
|
| 47 |
(0, 0, 255), 2, cv2.LINE_AA, False)
|
| 48 |
# return results
|
| 49 |
+
|
| 50 |
+
"""
|
| 51 |
|
| 52 |
demo = gr.Interface(
|
| 53 |
+
detect_faces_in_video,
|
| 54 |
#gr.Image(source="webcam", streaming=True, flip=True),
|
| 55 |
gr.Image(source="webcam", streaming=True),
|
| 56 |
"image",
|