pushpinder06 commited on
Commit
006bb51
·
verified ·
1 Parent(s): 7b9561d

Create app.py

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