Spaces:
Sleeping
Sleeping
Update app.py
Browse files107 unmodified lines10810911011111111211311311411511511611711813 unmodified lines13213313413513513613713813913714014114214314414514637 unmodified lines18418518618718818919019119219319419519619719819920042 unmodified lines24324424524622924724824925071 unmodified lines322323324307325326309327328329330312331332314315316333334335336337319338339340341107 unmodified lines total = round(0.55 * focus_score + 0.20 * spread_score + 0.25 * readability_score) total = max(0, min(100, total)) if total >= 75: grade = "Good" grade = "Strong" elif total >= 50: grade = "Fair" grade = "Good Start" else: grade = "Needs Work" grade = "Room to Grow" return total, grade
13 unmodified lines tips.append("Very little of the design pulls attention beyond the main hotspot. Secondary elements may go unnoticed by viewers.")
if read['contrast_issues'] > 0: tips.append(f"Fix contrast on {read['contrast_issues']} text element(s) - darken text or lighten its background to reach 4.5:1 minimum.") if read['contrast_issues'] > 5: tips.append(f"A quick win: {read['contrast_issues']} text elements could read more clearly. The good news - the pattern (see white boxes marked \"Low contrast\" on the image) suggests one color choice affects most of them, so a single tweak will likely fix most at once.") else: tips.append(f"{read['contrast_issues']} text element(s) could be easier to read - see the white boxes marked \"Low contrast\" on the image above, then darken the text or lighten its background.") if read['small_text_issues'] > 0: tips.append(f"Increase size on {read['small_text_issues']} text element(s) - text under ~1.2% of image height risks being unreadable.") if read['small_text_issues'] > 5: tips.append(f"Another quick win: {read['small_text_issues']} text elements are a bit small. Likely one font-size setting affects most of them, so this is usually a fast fix.") else: tips.append(f"{read['small_text_issues']} text element(s) are a bit small - see the white boxes marked \"Small text\" on the image above.")
if not tips: tips.append("No major issues detected - this design is in solid shape.")37 unmodified lines return (lighter + 0.05) / (darker + 0.05)
def contrast_severity_label(ratio): if ratio < 1.5: return "could be much clearer" elif ratio < 2.5: return "could be clearer" elif ratio < 3.5: return "slightly less clear than ideal" else: return "close to the recommended level"
def sample_text_and_bg_color(img_arr, x, y, w, h): pad = max(2, int(h * 0.3)) y0, y1 = max(0, y - pad), min(img_arr.shape[0], y + h + pad)42 unmodified lines if ratio < 4.5: contrast_issues += 1 if len(issue_lines) < 5: severity = contrast_severity_label(ratio) issue_lines.append(f"- Low contrast on \"{word}\" ({ratio:.1f}:1, needs 4.5:1 minimum)") issue_lines.append(f"- \"{word}\" is {severity} ({ratio:.1f}:1, needs 4.5:1 minimum)") issue_boxes.append({"box": (x, y, w, h), "label": "Low contrast"}) if size_pct < 1.2: small_text_issues += 171 unmodified lines if read['words_checked'] == 0: summary += "no text detected\n" elif read['contrast_issues'] == 0 and read['small_text_issues'] == 0: summary += "clean (0 issues)\n" summary += "clean, no changes needed\n" else: summary += f"{read['contrast_issues'] + read['small_text_issues']} issue(s) found\n" total_issues = read['contrast_issues'] + read['small_text_issues'] summary += f"{total_issues} easy improvement(s) spotted - see below\n"
if read['issue_lines']: summary += "\n**Readability details:**\n" + "\n".join(read['issue_lines']) + "\n" summary += "\n**A few examples:**\n" + "\n".join(read['issue_lines']) + "\n" summary += ( "\n*Note: contrast is estimated automatically and can misread text sitting on " "busy or gradient backgrounds. If a flagged item looks clearly readable to your " "eye, treat it as a false positive.*\n" "\n*Note: this is automated and can occasionally flag text that's actually fine, " "especially on busy or gradient backgrounds - if something flagged looks perfectly " "readable to your eye, trust your eye.*\n" )
summary += "\n**How to Improve:**\n" summary += "\n**How to Improve:** *(common and usually quick to fix)*\n" for tip in tips: summary += f"- {tip}\n"
app.py+32-13