Rasleen commited on
Commit
d685fea
·
verified ·
1 Parent(s): 63316e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2
3
+ import gradio as gr
4
+ from PIL import Image
5
+ def detect_faces(image):
6
+ image_np= np.array(image)
7
+ gray_image= cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
8
+ face_cascade= cv2.CascadeClassifier(cv2.data.haarcascades +
9
+ "haarcascade_frontalface_default.xml")
10
+ faces = face_cascade.detectMultiScale(gray_image,
11
+ scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
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
+ iface= gr.Interface(fn=detect_faces,inputs="image",outputs="image",title="Face Detection",description="Upload an image, and the model will detect faces and draw bounding boxes around them.",)
17
+ iface.launch()
18
+