Spaces:
Sleeping
Sleeping
JANGALA SAKETH commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import face_recognition
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def detect_faces(image):
|
| 6 |
+
image = np.array(image)
|
| 7 |
+
locations = face_recognition.face_locations(image)
|
| 8 |
+
encodings = face_recognition.face_encodings(image, locations)
|
| 9 |
+
|
| 10 |
+
faces = []
|
| 11 |
+
for (top, right, bottom, left), encoding in zip(locations, encodings):
|
| 12 |
+
cx = (left + right) / 2
|
| 13 |
+
cy = (top + bottom) / 2
|
| 14 |
+
faces.append({
|
| 15 |
+
"cx": cx,
|
| 16 |
+
"cy": cy,
|
| 17 |
+
"box": {
|
| 18 |
+
"top": top,
|
| 19 |
+
"right": right,
|
| 20 |
+
"bottom": bottom,
|
| 21 |
+
"left": left
|
| 22 |
+
},
|
| 23 |
+
"embedding": encoding.tolist()
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
return faces
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=detect_faces,
|
| 30 |
+
inputs=gr.Image(type="pil"),
|
| 31 |
+
outputs="json"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
iface.launch()
|