Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -109,9 +109,9 @@ def classify_zip_and_analyze_color(zip_file):
|
|
| 109 |
except Exception:
|
| 110 |
continue
|
| 111 |
|
| 112 |
-
# Thumbnail for gallery
|
| 113 |
thumb = image.copy()
|
| 114 |
-
thumb.
|
| 115 |
thumbnails.append(thumb)
|
| 116 |
|
| 117 |
# Classification
|
|
@@ -196,7 +196,7 @@ def classify_zip_and_analyze_color(zip_file):
|
|
| 196 |
buf2.seek(0)
|
| 197 |
plot2_img = Image.open(buf2)
|
| 198 |
|
| 199 |
-
# 3. Gender distribution
|
| 200 |
ages = []
|
| 201 |
gender_confidence = {"Man": 0, "Woman": 0}
|
| 202 |
for face_list in df["Face Info"]:
|
|
@@ -221,12 +221,26 @@ def classify_zip_and_analyze_color(zip_file):
|
|
| 221 |
buf3.seek(0)
|
| 222 |
plot3_img = Image.open(buf3)
|
| 223 |
|
| 224 |
-
# 4. Age distribution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
fig4, ax4 = plt.subplots()
|
| 226 |
-
|
| 227 |
-
ax4.
|
|
|
|
| 228 |
ax4.set_xlabel("Age")
|
| 229 |
ax4.set_ylabel("Count")
|
|
|
|
| 230 |
buf4 = io.BytesIO()
|
| 231 |
plt.savefig(buf4, format="png")
|
| 232 |
plt.close(fig4)
|
|
@@ -248,7 +262,7 @@ demo = gr.Interface(
|
|
| 248 |
gr.Image(type="pil", label="Basic Color Frequency"),
|
| 249 |
gr.Image(type="pil", label="Top Prediction Distribution"),
|
| 250 |
gr.Image(type="pil", label="Gender Distribution (Weighted ≤90%)"),
|
| 251 |
-
gr.Image(type="pil", label="Age Distribution"),
|
| 252 |
],
|
| 253 |
title="Image Classifier with Color & Face Analysis",
|
| 254 |
description="Upload a ZIP of images. Classifies images, analyzes dominant color, detects faces, and displays thumbnails.",
|
|
|
|
| 109 |
except Exception:
|
| 110 |
continue
|
| 111 |
|
| 112 |
+
# Thumbnail for gallery (higher-quality)
|
| 113 |
thumb = image.copy()
|
| 114 |
+
thumb = thumb.resize((200, 200), Image.LANCZOS)
|
| 115 |
thumbnails.append(thumb)
|
| 116 |
|
| 117 |
# Classification
|
|
|
|
| 196 |
buf2.seek(0)
|
| 197 |
plot2_img = Image.open(buf2)
|
| 198 |
|
| 199 |
+
# 3. Gender distribution (weighted)
|
| 200 |
ages = []
|
| 201 |
gender_confidence = {"Man": 0, "Woman": 0}
|
| 202 |
for face_list in df["Face Info"]:
|
|
|
|
| 221 |
buf3.seek(0)
|
| 222 |
plot3_img = Image.open(buf3)
|
| 223 |
|
| 224 |
+
# 4. Age distribution by gender
|
| 225 |
+
ages_men = []
|
| 226 |
+
ages_women = []
|
| 227 |
+
for face_list in df["Face Info"]:
|
| 228 |
+
for face in face_list:
|
| 229 |
+
age = face["age"]
|
| 230 |
+
gender_dict = face["gender"]
|
| 231 |
+
gender = max(gender_dict, key=gender_dict.get)
|
| 232 |
+
if gender.lower() == "man":
|
| 233 |
+
ages_men.append(age)
|
| 234 |
+
else:
|
| 235 |
+
ages_women.append(age)
|
| 236 |
+
|
| 237 |
fig4, ax4 = plt.subplots()
|
| 238 |
+
bins = range(0, 101, 5)
|
| 239 |
+
ax4.hist([ages_men, ages_women], bins=bins, color=["lightblue", "pink"], label=["Men", "Women"], stacked=False)
|
| 240 |
+
ax4.set_title("Age Distribution by Gender")
|
| 241 |
ax4.set_xlabel("Age")
|
| 242 |
ax4.set_ylabel("Count")
|
| 243 |
+
ax4.legend()
|
| 244 |
buf4 = io.BytesIO()
|
| 245 |
plt.savefig(buf4, format="png")
|
| 246 |
plt.close(fig4)
|
|
|
|
| 262 |
gr.Image(type="pil", label="Basic Color Frequency"),
|
| 263 |
gr.Image(type="pil", label="Top Prediction Distribution"),
|
| 264 |
gr.Image(type="pil", label="Gender Distribution (Weighted ≤90%)"),
|
| 265 |
+
gr.Image(type="pil", label="Age Distribution by Gender"),
|
| 266 |
],
|
| 267 |
title="Image Classifier with Color & Face Analysis",
|
| 268 |
description="Upload a ZIP of images. Classifies images, analyzes dominant color, detects faces, and displays thumbnails.",
|