Spaces:
Runtime error
Runtime error
chore: Convert image format for DeepFace analysis
Browse files
app.py
CHANGED
@@ -4,30 +4,27 @@ import cv2
|
|
4 |
import numpy as np
|
5 |
|
6 |
def analyze_frame(frame):
|
7 |
-
|
|
|
|
|
8 |
if result:
|
9 |
gender = result[0]['gender']
|
10 |
else:
|
11 |
gender = "No face detected"
|
12 |
-
return frame,
|
13 |
|
14 |
-
def
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
break
|
20 |
-
yield frame
|
21 |
-
camera.release()
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
video_stream.stream(fn=analyze_frame, inputs=video_stream, outputs=result_image)
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
-
demo.launch()
|
|
|
4 |
import numpy as np
|
5 |
|
6 |
def analyze_frame(frame):
|
7 |
+
# Convert frame from BGR to RGB format for DeepFace
|
8 |
+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
9 |
+
result = DeepFace.analyze(frame_rgb, actions=['gender'], enforce_detection=False)
|
10 |
if result:
|
11 |
gender = result[0]['gender']
|
12 |
else:
|
13 |
gender = "No face detected"
|
14 |
+
return frame, gender
|
15 |
|
16 |
+
def process_webcam_image(image):
|
17 |
+
# Convert the image to a format suitable for DeepFace
|
18 |
+
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
19 |
+
frame, gender = analyze_frame(image)
|
20 |
+
return frame, gender
|
|
|
|
|
|
|
21 |
|
22 |
+
demo = gr.Interface(
|
23 |
+
fn=process_webcam_image,
|
24 |
+
inputs=gr.Image(source="webcam", streaming=True),
|
25 |
+
outputs=[gr.Image(), gr.Textbox()],
|
26 |
+
live=True
|
27 |
+
)
|
|
|
|
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
+
demo.launch()
|