sakthi07 commited on
Commit
77829f2
·
1 Parent(s): 20c82c9

Uploaded app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2
3
+ import gradio as gr
4
+
5
+ def detect_face(img):
6
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
7
+ path = "haarcascade_frontalface_default.xml"
8
+ face_cascade = cv2.CascadeClassifier(path)
9
+ faces = face_cascade.detectMultiScale(gray, scaleFactor=1.05, minNeighbors=17, minSize=(40, 40))
10
+ return len(faces)
11
+
12
+ def face_detector(image):
13
+ img_np = np.array(image)
14
+ img = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
15
+ # img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
16
+ num_faces = detect_face(img)
17
+ return num_faces
18
+
19
+ title = "Face Detector: Counts the Number of Faces in an Image\n\n"
20
+ title += "<span style='font-size: smaller;'>Subtitle: The face detector counts the number of faces and returns it. It works fairly well. This is built based on Haar Cascade Algorithm.</span>"
21
+
22
+ iface = gr.Interface(
23
+ fn=face_detector,
24
+ inputs=gr.inputs.Image(type="pil", label="Upload an Image"),
25
+ outputs="text",
26
+ title=title,
27
+ examples=[
28
+ ["sample_faces/angry_face.jpg"],
29
+ ["sample_faces/beard_man.jpg"],
30
+ ["sample_faces/bw_face.jpg"],
31
+ ["sample_faces/faces.jpeg"],
32
+ ["sample_faces/glass_man.jpg"],
33
+ ["sample_faces/normal_face.jpg"],
34
+ ["sample_faces/red_dress.jpg"]
35
+ ],
36
+ allow_flagging=False,
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ iface.launch()