Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import cv2
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 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 |
-
|
| 34 |
-
|
|
|
|
| 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()
|