Spaces:
Runtime error
Runtime error
Upload Deepface_analyze.py
Browse files- Deepface_analyze.py +34 -0
Deepface_analyze.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pathlib
|
3 |
+
from deepface import DeepFace
|
4 |
+
|
5 |
+
#db_path='https://huggingface.co/spaces/ipvikas/ImageProcessing/blob/main/MyPhotos'
|
6 |
+
|
7 |
+
#db_path='https://huggingface.co/spaces/ipvikas/ImageProcessing/commit/c65e002550d4c148da1bb94c114373b2272f4d88#d2h-994579/'
|
8 |
+
db_path= [[path.as_posix()] for path in sorted(pathlib.Path('Image_DATA').rglob('*.j*g'))]
|
9 |
+
|
10 |
+
#from datasets import load_dataset
|
11 |
+
#db_path= load_dataset("imagefolder", data_files=db_path)
|
12 |
+
|
13 |
+
|
14 |
+
import pandas as pd
|
15 |
+
def get_deepface(image):
|
16 |
+
df = DeepFace.find(img_path=image, db_path=db_path)
|
17 |
+
d = DeepFace.analyze(img_path=image)
|
18 |
+
#new_list = zip(d.keys(), d.values())
|
19 |
+
#new_list = list(new_list)
|
20 |
+
return d
|
21 |
+
|
22 |
+
description = "Deepface is a lightweight face recognition and facial attribute analysis (age, gender, emotion and race) framework for python. It is a hybrid face recognition framework wrapping state-of-the-art models: VGG-Face, Google FaceNet, OpenFace, Facebook DeepFace, DeepID, ArcFace and Dlib."
|
23 |
+
|
24 |
+
facial_attribute_demo = gr.Interface(
|
25 |
+
fn=get_deepface,
|
26 |
+
inputs="image",
|
27 |
+
outputs=['text'],
|
28 |
+
title="face recognition and facial attribute analysis",
|
29 |
+
description=description,
|
30 |
+
enable_queue=True,
|
31 |
+
examples=[["10Jan_1.jpeg"]],
|
32 |
+
cache_examples=False)
|
33 |
+
|
34 |
+
facial_attribute_demo.launch()
|