yahyaahmed commited on
Commit
1db04fd
·
verified ·
1 Parent(s): 7de2f52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -15,6 +15,7 @@ def detect_faces(image):
15
  # Run inference
16
  output = model(image)
17
  detections = Detections.from_ultralytics(output[0])
 
18
 
19
  # Convert PIL image to OpenCV format
20
  image_np = np.array(image)
@@ -27,13 +28,17 @@ def detect_faces(image):
27
 
28
  # Convert back to PIL image
29
  result_image = Image.fromarray(cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB))
30
- return result_image
 
31
 
32
  # Gradio Interface
33
  demo = gr.Interface(
34
  fn=detect_faces,
35
  inputs=gr.Image(type="pil", label="Upload Image"),
36
- outputs=gr.Image(type="pil", label="Detected Faces"),
 
 
 
37
  title="Face Detection with YOLOv8",
38
  description="Drag and drop an image or click to upload. The model will detect faces using YOLOv8.",
39
  live=False
 
15
  # Run inference
16
  output = model(image)
17
  detections = Detections.from_ultralytics(output[0])
18
+ num_faces = len(detections.xyxy)
19
 
20
  # Convert PIL image to OpenCV format
21
  image_np = np.array(image)
 
28
 
29
  # Convert back to PIL image
30
  result_image = Image.fromarray(cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB))
31
+
32
+ return result_image, num_faces
33
 
34
  # Gradio Interface
35
  demo = gr.Interface(
36
  fn=detect_faces,
37
  inputs=gr.Image(type="pil", label="Upload Image"),
38
+ outputs=[
39
+ gr.Image(type="pil", label="Detected Faces"),
40
+ gr.Number(label="Face Count")
41
+ ],
42
  title="Face Detection with YOLOv8",
43
  description="Drag and drop an image or click to upload. The model will detect faces using YOLOv8.",
44
  live=False