paresh95 commited on
Commit
c3143ea
·
1 Parent(s): 0f7be63

PS | Enhanced theme and basic front end changes

Browse files
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from src.face_texture import GetFaceTexture
3
  from src.face_symmetry import GetFaceSymmetry
4
  from src.face_demographics import GetFaceDemographics
@@ -12,21 +13,26 @@ def combined_fn(input_image):
12
  proportion_results = GetFaceProportions().main(input_image)
13
  return (*texture_results, *symmetry_results, demographics_results, *proportion_results)
14
 
 
15
 
16
  iface = gr.Interface(
17
  fn=combined_fn,
18
- inputs=gr.inputs.Image(type="pil"),
19
  outputs=[
20
- gr.outputs.Image(type="pil"), # From GetFaceTexture
21
- gr.outputs.Image(type="pil"), # From GetFaceTexture
22
- "text", # From GetFaceTexture
23
- gr.outputs.Image(type="pil"), # From GetFaceSymmetry
24
- "text", # From GetFaceSymmetry
25
- "text", # From GetFaceDemographics
26
- "text", # From GetFaceProportions
27
- "text", # From GetFaceProportions
28
- gr.outputs.Image(type="pil"), # From GetFaceProportions
29
  ],
 
 
 
 
30
  )
31
 
32
  iface.launch()
 
1
  import gradio as gr
2
+ import os
3
  from src.face_texture import GetFaceTexture
4
  from src.face_symmetry import GetFaceSymmetry
5
  from src.face_demographics import GetFaceDemographics
 
13
  proportion_results = GetFaceProportions().main(input_image)
14
  return (*texture_results, *symmetry_results, demographics_results, *proportion_results)
15
 
16
+ gigi_hadid = os.path.join(os.path.dirname(__file__), "data/gigi_hadid.webp")
17
 
18
  iface = gr.Interface(
19
  fn=combined_fn,
20
+ inputs=gr.Image(type="pil", label="Upload Face Image", value=gigi_hadid),
21
  outputs=[
22
+ gr.Image(type="pil", label="Extracted face"),
23
+ gr.Image(type="pil", label="Extracted face texture"),
24
+ "json",
25
+ gr.Image(type="pil", label="Face symmetry"),
26
+ "json",
27
+ "json",
28
+ "json",
29
+ "json",
30
+ gr.Image(type="pil", label="Face landmarks"),
31
  ],
32
+ title="Advanced Facial Feature Detector",
33
+ description="A comprehensive tool for detailed face analysis. Please upload a clear face image for best results.",
34
+ theme=gr.themes.Soft(),
35
+ live=False,
36
  )
37
 
38
  iface.launch()
notebooks/facial_age_gender.ipynb CHANGED
@@ -515,11 +515,6 @@
515
  "# Other\n",
516
  "- Dataset used to train model: https://talhassner.github.io/home/projects/Adience/Adience-data.html#agegender"
517
  ]
518
- },
519
- {
520
- "cell_type": "markdown",
521
- "metadata": {},
522
- "source": []
523
  }
524
  ],
525
  "metadata": {
 
515
  "# Other\n",
516
  "- Dataset used to train model: https://talhassner.github.io/home/projects/Adience/Adience-data.html#agegender"
517
  ]
 
 
 
 
 
518
  }
519
  ],
520
  "metadata": {
src/face_demographics.py CHANGED
@@ -68,7 +68,7 @@ class GetFaceDemographics:
68
  output = model(**inputs)
69
  proba = output.logits.softmax(1)
70
  preds = proba.argmax(1)
71
- age_confidence_score = max(proba[0]).item()
72
  age = id2label[int(preds)]
73
  return age, age_confidence_score
74
 
@@ -86,7 +86,7 @@ class GetFaceDemographics:
86
  output = model(**inputs)
87
  proba = output.logits.softmax(1)
88
  preds = proba.argmax(1)
89
- gender_confidence_score = max(proba[0]).item()
90
  gender = id2label[int(preds)]
91
  return gender, gender_confidence_score
92
 
 
68
  output = model(**inputs)
69
  proba = output.logits.softmax(1)
70
  preds = proba.argmax(1)
71
+ age_confidence_score = round(max(proba[0]).item(), 2)
72
  age = id2label[int(preds)]
73
  return age, age_confidence_score
74
 
 
86
  output = model(**inputs)
87
  proba = output.logits.softmax(1)
88
  preds = proba.argmax(1)
89
+ gender_confidence_score = round(max(proba[0]).item(), 2)
90
  gender = id2label[int(preds)]
91
  return gender, gender_confidence_score
92
 
src/face_proportions.py CHANGED
@@ -107,7 +107,9 @@ class GetFaceProportions:
107
  gray_image = self.preprocess_image(image)
108
  shape, image = self.detect_face_landmarks(gray_image)
109
  golden_ratios = self.compute_golden_ratios(shape)
 
110
  equal_ratios = self.compute_equal_ratios(shape)
 
111
  image = PILImage.fromarray(image)
112
  return golden_ratios, equal_ratios, image
113
 
 
107
  gray_image = self.preprocess_image(image)
108
  shape, image = self.detect_face_landmarks(gray_image)
109
  golden_ratios = self.compute_golden_ratios(shape)
110
+ golden_ratios = {k: round(v, 2) for k, v in golden_ratios.items()}
111
  equal_ratios = self.compute_equal_ratios(shape)
112
+ equal_ratios = {k: round(v, 2) for k, v in equal_ratios.items()}
113
  image = PILImage.fromarray(image)
114
  return golden_ratios, equal_ratios, image
115
 
src/face_symmetry.py CHANGED
@@ -133,6 +133,7 @@ class GetFaceSymmetry:
133
 
134
  full_face = np.hstack((best_left_half, best_right_half))
135
  full_face = PILImage.fromarray(full_face)
 
136
  return full_face, best_face_data
137
 
138
 
 
133
 
134
  full_face = np.hstack((best_left_half, best_right_half))
135
  full_face = PILImage.fromarray(full_face)
136
+ best_face_data = {k: float(round(v, 2)) for k, v in best_face_data.items()}
137
  return full_face, best_face_data
138
 
139
 
src/face_texture.py CHANGED
@@ -57,7 +57,7 @@ class GetFaceTexture:
57
  face_image = self.get_face(gray_image)
58
  lbp, std = self.get_face_texture(face_image)
59
  face_texture_image = self.postprocess_image(lbp)
60
- return face_texture_image, face_image, std
61
 
62
 
63
  if __name__ == "__main__":
 
57
  face_image = self.get_face(gray_image)
58
  lbp, std = self.get_face_texture(face_image)
59
  face_texture_image = self.postprocess_image(lbp)
60
+ return face_image, face_texture_image, {"Texture std": round(std, 2)}
61
 
62
 
63
  if __name__ == "__main__":