Abraham E. Tavarez commited on
Commit
4c7f58c
·
1 Parent(s): 99c30b7

verify_face, analyze_face functions and extract embedding functions tested

Browse files
.python-version CHANGED
@@ -1 +1 @@
1
- 3.13
 
1
+ 3.12
assets/demo_files/bezos1.jpg ADDED
assets/demo_files/diesel1.jpg ADDED
assets/demo_files/gates1.jpg ADDED
detector/face.py CHANGED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from deepface import DeepFace
2
+ import cv2
3
+ import os
4
+
5
+ def verify_faces(img1_path, img2_path, model_name="Facenet", detector_backend="opencv"):
6
+ """
7
+ Compares two face images and returns whether they belong to the same person.
8
+ """
9
+ try:
10
+ result = DeepFace.verify(
11
+ img1_path,
12
+ img2_path,
13
+ model_name=model_name,
14
+ detector_backend=detector_backend,
15
+ enforce_detection=True
16
+ )
17
+
18
+ return {
19
+ "verified": result["verified"],
20
+ "distance": result["distance"],
21
+ "threshold": result["threshold"],
22
+ "model": model_name
23
+ }
24
+
25
+ except Exception as e:
26
+ return {"error": str(e)}
27
+
28
+
29
+ def analyze_face(img_path, actions=["age", "gender", "emotion"], detector_backend="opencv"):
30
+ """
31
+ Analyze attributes of a face in the image.
32
+ """
33
+ try:
34
+ analysis = DeepFace.analyze(
35
+ img_path=img_path,
36
+ actions=actions,
37
+ detector_backend=detector_backend,
38
+ enforce_detection=True
39
+ )
40
+
41
+ return analysis[0] if isinstance(analysis, list) else analysis
42
+
43
+ except Exception as e:
44
+ return {"error": str(e)}
45
+
46
+ def extract_embedding(img_path, model_name="Facenet", detector_backend="opencv"):
47
+ """
48
+ Extract a face embedding from an image.
49
+ """
50
+ try:
51
+ embedding = DeepFace.represent(
52
+ img_path=img_path,
53
+ model_name=model_name,
54
+ detector_backend=detector_backend,
55
+ enforce_detection=True
56
+ )
57
+
58
+ return embedding[0] if isinstance(embedding, list) else embedding
59
+
60
+ except Exception as e:
61
+ return {"error": str(e)}
pyproject.toml CHANGED
@@ -3,7 +3,10 @@ name = "deepfake-watchdog"
3
  version = "0.1.0"
4
  description = "Add your description here"
5
  readme = "README.md"
6
- requires-python = ">=3.13"
7
  dependencies = [
 
8
  "gradio[mcp]>=5.32.1",
 
 
9
  ]
 
3
  version = "0.1.0"
4
  description = "Add your description here"
5
  readme = "README.md"
6
+ requires-python = ">=3.12"
7
  dependencies = [
8
+ "deepface>=0.0.93",
9
  "gradio[mcp]>=5.32.1",
10
+ "opencv-python-headless>=4.11.0.86",
11
+ "tf-keras>=2.19.0",
12
  ]
test.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from detector.face import verify_faces, analyze_face
2
+
3
+ # result = verify_faces('./assets/demo_files/bezos1.jpg', './assets/demo_files/diesel1.jpg')
4
+ # print(result)
5
+
6
+ analysis = analyze_face('./assets/demo_files/gates1.jpg')
7
+ print(analysis)
uv.lock CHANGED
The diff for this file is too large to render. See raw diff