pushpinder06 commited on
Commit
0050629
·
verified ·
1 Parent(s): 2a6e1e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -3,30 +3,28 @@ import cv2
3
  import gradio as gr
4
  from PIL import Image
5
 
6
-
7
  # Load Haar Cascade classifier
8
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
9
- # slider=gr.Slider(minimum=1,maximum=2,step=.1,label="Adjust the scale factor.")
10
  # Face Detection Function
11
- def detect_faces(image_np):
12
- img=np.array(gray_image)
13
  # Convert image to grayscale
14
- gray_image = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
15
 
16
  # Detect faces
17
- faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.3, minNeighbors=5, minSize=(30, 30))
18
 
19
  # Draw rectangles around faces
20
  for (x, y, w, h) in faces:
21
  cv2.rectangle(image_np, (x, y), (x + w, y + h), (0, 255, 0), 2)
22
 
23
- return img,
24
 
25
  # Create Gradio Interface
26
  iface = gr.Interface(
27
  fn=detect_faces,
28
- inputs="image",
29
- outputs="image",
30
  title="Face Detection",
31
  description="Upload an image, and the model will detect faces and draw bounding boxes around them."
32
  )
 
3
  import gradio as gr
4
  from PIL import Image
5
 
 
6
  # Load Haar Cascade classifier
7
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
8
+
9
  # Face Detection Function
10
+ def detect_faces(image_np,slider):
 
11
  # Convert image to grayscale
12
+ gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
13
 
14
  # Detect faces
15
+ faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
16
 
17
  # Draw rectangles around faces
18
  for (x, y, w, h) in faces:
19
  cv2.rectangle(image_np, (x, y), (x + w, y + h), (0, 255, 0), 2)
20
 
21
+ return image_np, len(faces)
22
 
23
  # Create Gradio Interface
24
  iface = gr.Interface(
25
  fn=detect_faces,
26
+ inputs=["image",gr.Slider(minimum=1,maximum=2,step=.1,label= "adjust the scaleFactor")],
27
+ outputs=["image",gr.Label("faces count")],
28
  title="Face Detection",
29
  description="Upload an image, and the model will detect faces and draw bounding boxes around them."
30
  )