Spaces:
Sleeping
Sleeping
Update app.py
Browse files107 unmodified lines10810911011111211311411511611711813 unmodified lines13213313413513613713813914037 unmodified lines17817918018118218342 unmodified lines22622722822923023123271 unmodified lines304305306307308309310311312313314315316317318319320321322107 unmodified linestotal = round(0.55 * focus_score + 0.20 * spread_score + 0.25 * readability_score)total = max(0, min(100, total))if total >= 75:grade = "Good"elif total >= 50:grade = "Fair"else:grade = "Needs Work"return total, grade13 unmodified linestips.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['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 not tips:tips.append("No major issues detected - this design is in solid shape.")37 unmodified linesreturn (lighter + 0.05) / (darker + 0.05)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 linesif ratio < 4.5:contrast_issues += 1if len(issue_lines) < 5:issue_lines.append(f"- Low contrast on \"{word}\" ({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 linesif 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"else:summary += f"{read['contrast_issues'] + read['small_text_issues']} issue(s) found\n"if read['issue_lines']:summary += "\n**Readability details:**\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")summary += "\n**How to Improve:**\n"for tip in tips:summary += f"- {tip}\n"107 unmodified lines10810911011111211311411511611711813 unmodified lines13213313413513613713813914014114214314414514637 unmodified lines18418518618718818919019119219319419519619719819920042 unmodified lines24324424524624724824925071 unmodified lines322323324325326327328329330331332333334335336337338339340341107 unmodified linestotal = round(0.55 * focus_score + 0.20 * spread_score + 0.25 * readability_score)total = max(0, min(100, total))if total >= 75:grade = "Strong"elif total >= 50:grade = "Good Start"else:grade = "Room to Grow"return total, grade13 unmodified linestips.append("Very little of the design pulls attention beyond the main hotspot. Secondary elements may go unnoticed by viewers.")if read['contrast_issues'] > 0: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: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 linesreturn (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 linesif ratio < 4.5:contrast_issues += 1if len(issue_lines) < 5:severity = contrast_severity_label(ratio)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 linesif read['words_checked'] == 0:summary += "no text detected\n"elif read['contrast_issues'] == 0 and read['small_text_issues'] == 0:summary += "clean, no changes needed\n"else: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**A few examples:**\n" + "\n".join(read['issue_lines']) + "\n"summary += ("\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:** *(common and usually quick to fix)*\n"for tip in tips:summary += f"- {tip}\n"
app.py+32-13