MarcosRodrigo commited on
Commit
efdc92d
·
verified ·
1 Parent(s): 834b2a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -29
app.py CHANGED
@@ -1,34 +1,13 @@
1
  import gradio as gr
2
- import cv2
3
 
4
- # Load the pre-trained Haar Cascade classifier for face detection
5
- face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
6
 
7
- def detect_faces(image):
8
- # Convert RGB image to OpenCV BGR format
9
- img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
10
-
11
- # Convert to grayscale for face detection
12
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
13
-
14
- # Perform face detection
15
- faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
16
-
17
- # Draw rectangles around detected faces
18
- for (x, y, w, h) in faces:
19
- cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
20
-
21
- # Convert back to RGB for display
22
- return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
23
-
24
- # Use gr.Video with live=True for live webcam feed
25
- webcam_interface = gr.Interface(
26
- fn=detect_faces,
27
- inputs=gr.Video(streaming=True, live=True), # Use `live=True` instead of `source="webcam"`
28
- outputs="image",
29
- title="Live Webcam Face Detection",
30
- description="Displays the live feed from your webcam and detects faces in real-time."
31
  )
32
 
33
- # Launch the Gradio app
34
- webcam_interface.launch()
 
1
  import gradio as gr
 
2
 
3
+ def snap(image, video):
4
+ return [image, video]
5
 
6
+ demo = gr.Interface(
7
+ snap,
8
+ [gr.Image(sources=["webcam"]), gr.Video(sources=["webcam"])],
9
+ ["image", "video"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  )
11
 
12
+ if __name__ == "__main__":
13
+ demo.launch()