Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,6 +60,24 @@ def get_dominant_color(image,num_colors=5):
|
|
| 60 |
hex_color = f"#{dominant_color[0]:02x}{dominant_color[1]:02x}{dominant_color[2]:02x}"
|
| 61 |
return dominant_color, hex_color
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# ---------------------------
|
| 64 |
# Core analysis
|
| 65 |
# ---------------------------
|
|
@@ -103,25 +121,17 @@ def classify_zip_and_analyze_color(zip_file):
|
|
| 103 |
img_cv2, actions=["age","gender","emotion"], enforce_detection=False
|
| 104 |
)
|
| 105 |
|
| 106 |
-
# Ensure
|
| 107 |
if isinstance(detected_faces, dict):
|
| 108 |
detected_faces = [detected_faces]
|
| 109 |
|
| 110 |
for f in detected_faces:
|
| 111 |
-
|
| 112 |
-
if gender in ["man", "male"]:
|
| 113 |
-
gender_fr = "Homme"
|
| 114 |
-
elif gender in ["woman", "female"]:
|
| 115 |
-
gender_fr = "Femme"
|
| 116 |
-
else:
|
| 117 |
-
gender_fr = "Inconnu"
|
| 118 |
-
|
| 119 |
faces_data.append({
|
| 120 |
"age": f.get("age", -1),
|
| 121 |
"gender": gender_fr,
|
| 122 |
"emotion": f.get("dominant_emotion", "Unknown")
|
| 123 |
})
|
| 124 |
-
|
| 125 |
except:
|
| 126 |
faces_data = []
|
| 127 |
|
|
|
|
| 60 |
hex_color = f"#{dominant_color[0]:02x}{dominant_color[1]:02x}{dominant_color[2]:02x}"
|
| 61 |
return dominant_color, hex_color
|
| 62 |
|
| 63 |
+
# ---------------------------
|
| 64 |
+
# Gender normalization
|
| 65 |
+
# ---------------------------
|
| 66 |
+
def normalize_gender(raw_gender):
|
| 67 |
+
if raw_gender is None:
|
| 68 |
+
return "Inconnu"
|
| 69 |
+
g = str(raw_gender).lower()
|
| 70 |
+
if g in ["man", "male", "m"]:
|
| 71 |
+
return "Homme"
|
| 72 |
+
elif g in ["woman", "female", "f"]:
|
| 73 |
+
return "Femme"
|
| 74 |
+
elif g in ["homme"]:
|
| 75 |
+
return "Homme"
|
| 76 |
+
elif g in ["femme"]:
|
| 77 |
+
return "Femme"
|
| 78 |
+
else:
|
| 79 |
+
return "Inconnu"
|
| 80 |
+
|
| 81 |
# ---------------------------
|
| 82 |
# Core analysis
|
| 83 |
# ---------------------------
|
|
|
|
| 121 |
img_cv2, actions=["age","gender","emotion"], enforce_detection=False
|
| 122 |
)
|
| 123 |
|
| 124 |
+
# Ensure we have a list
|
| 125 |
if isinstance(detected_faces, dict):
|
| 126 |
detected_faces = [detected_faces]
|
| 127 |
|
| 128 |
for f in detected_faces:
|
| 129 |
+
gender_fr = normalize_gender(f.get("gender") or f.get("dominant_gender"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
faces_data.append({
|
| 131 |
"age": f.get("age", -1),
|
| 132 |
"gender": gender_fr,
|
| 133 |
"emotion": f.get("dominant_emotion", "Unknown")
|
| 134 |
})
|
|
|
|
| 135 |
except:
|
| 136 |
faces_data = []
|
| 137 |
|