Mrlongpro commited on
Commit
f96b4e6
1 Parent(s): ef0e3bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import numpy as np
2
  import cv2
3
  import gradio as gr
4
- from PIL import Image
5
 
6
- def detect_faces(image):
7
- image_np = np.array(image)
8
  gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
9
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
10
  faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(10, 10))
11
- print("faces: ",faces)
 
 
 
12
  for (x, y, w, h) in faces:
13
  cv2.rectangle(image_np, (x, y), (x+w, y+h), (0, 255, 0), 2)
14
  return image_np
15
 
16
  interface = gr.Interface(
17
  fn=detect_faces,
18
- inputs="image",
19
  outputs="image",
20
  title="Face Detection with Haar Cascade",
21
- description="Upload an image, and the model will detect faces and draw bounding boxes around them.",
22
  )
23
  interface.launch()
 
1
  import numpy as np
2
  import cv2
3
  import gradio as gr
 
4
 
5
+ def detect_faces(image_file):
6
+ image_np = cv2.imread(image_file.name)
7
  gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
8
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
9
  faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(10, 10))
10
+ if len(faces) > 0:
11
+ print("Face detected!")
12
+ else:
13
+ print("No faces detected.")
14
  for (x, y, w, h) in faces:
15
  cv2.rectangle(image_np, (x, y), (x+w, y+h), (0, 255, 0), 2)
16
  return image_np
17
 
18
  interface = gr.Interface(
19
  fn=detect_faces,
20
+ inputs="file",
21
  outputs="image",
22
  title="Face Detection with Haar Cascade",
23
+ description="Upload an image file, and the model will detect faces and draw bounding boxes around them.",
24
  )
25
  interface.launch()