Spaces:
Running
Running
prince1604 commited on
Commit ·
c1d121b
1
Parent(s): a09c50d
Add short alt text detection (<15 chars) to reports
Browse files- src/analyzer.py +11 -2
src/analyzer.py
CHANGED
|
@@ -8,10 +8,12 @@ class ImageAnalyzer:
|
|
| 8 |
"""
|
| 9 |
total_images = 0
|
| 10 |
total_missing_alt = 0
|
|
|
|
| 11 |
pages_report = []
|
| 12 |
|
| 13 |
for page_url, images in site_data.items():
|
| 14 |
missing_images = []
|
|
|
|
| 15 |
for img in images:
|
| 16 |
total_images += 1
|
| 17 |
alt_text = img.get('alt')
|
|
@@ -24,18 +26,25 @@ class ImageAnalyzer:
|
|
| 24 |
# We will count empty string as missing alt text for SEO purposes.
|
| 25 |
missing_images.append(img['src'])
|
| 26 |
total_missing_alt += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
pages_report.append({
|
| 29 |
"page_url": page_url,
|
| 30 |
"missing_alt_count": len(missing_images),
|
| 31 |
-
"
|
|
|
|
|
|
|
| 32 |
})
|
| 33 |
|
| 34 |
return {
|
| 35 |
"summary": {
|
| 36 |
"total_pages_scanned": len(site_data),
|
| 37 |
"total_images_found": total_images,
|
| 38 |
-
"total_images_missing_alt": total_missing_alt
|
|
|
|
| 39 |
},
|
| 40 |
"details": pages_report
|
| 41 |
}
|
|
|
|
| 8 |
"""
|
| 9 |
total_images = 0
|
| 10 |
total_missing_alt = 0
|
| 11 |
+
total_short_alt = 0
|
| 12 |
pages_report = []
|
| 13 |
|
| 14 |
for page_url, images in site_data.items():
|
| 15 |
missing_images = []
|
| 16 |
+
short_alt_images = []
|
| 17 |
for img in images:
|
| 18 |
total_images += 1
|
| 19 |
alt_text = img.get('alt')
|
|
|
|
| 26 |
# We will count empty string as missing alt text for SEO purposes.
|
| 27 |
missing_images.append(img['src'])
|
| 28 |
total_missing_alt += 1
|
| 29 |
+
elif len(alt_text.strip()) < 15:
|
| 30 |
+
# Count short alt text (less than 15 chars)
|
| 31 |
+
short_alt_images.append({'src': img['src'], 'alt': alt_text})
|
| 32 |
+
total_short_alt += 1
|
| 33 |
|
| 34 |
pages_report.append({
|
| 35 |
"page_url": page_url,
|
| 36 |
"missing_alt_count": len(missing_images),
|
| 37 |
+
"short_alt_count": len(short_alt_images),
|
| 38 |
+
"images_without_alt": list(set(missing_images)),
|
| 39 |
+
"images_with_short_alt": short_alt_images
|
| 40 |
})
|
| 41 |
|
| 42 |
return {
|
| 43 |
"summary": {
|
| 44 |
"total_pages_scanned": len(site_data),
|
| 45 |
"total_images_found": total_images,
|
| 46 |
+
"total_images_missing_alt": total_missing_alt,
|
| 47 |
+
"total_images_short_alt": total_short_alt
|
| 48 |
},
|
| 49 |
"details": pages_report
|
| 50 |
}
|