Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -109,12 +109,17 @@ def compute_attention_scores(saliency_map):
|
|
| 109 |
|
| 110 |
|
| 111 |
def compute_readability_score(read):
|
|
|
|
|
|
|
| 112 |
penalty = 12 * math.sqrt(read['contrast_issues']) + 8 * math.sqrt(read['small_text_issues'])
|
| 113 |
return round(max(0, 100 - penalty), 1)
|
| 114 |
|
| 115 |
|
| 116 |
def compute_overall_grade(focus_score, spread_score, readability_score):
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
| 118 |
total = max(0, min(100, total))
|
| 119 |
if total >= 75:
|
| 120 |
grade = "Strong"
|
|
@@ -126,6 +131,13 @@ def compute_overall_grade(focus_score, spread_score, readability_score):
|
|
| 126 |
|
| 127 |
|
| 128 |
def explain_grade(focus_score, readability_score, read):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
total_issues = read['contrast_issues'] + read['small_text_issues']
|
| 130 |
weighted_focus_deficit = 0.55 * max(0, 100 - focus_score)
|
| 131 |
weighted_read_deficit = 0.25 * max(0, 100 - readability_score)
|
|
@@ -150,8 +162,11 @@ def coverage_description(spread_score):
|
|
| 150 |
|
| 151 |
|
| 152 |
def create_score_chart(focus_score, spread_score, readability_score):
|
| 153 |
-
labels = ["Clear Focal\nPoint", "Attention\nCoverage"
|
| 154 |
-
values = [focus_score, spread_score
|
|
|
|
|
|
|
|
|
|
| 155 |
colors = []
|
| 156 |
for v in values:
|
| 157 |
if v >= 75:
|
|
@@ -381,7 +396,7 @@ def analyze(pil_image, overlay_strength):
|
|
| 381 |
f"- Readability: "
|
| 382 |
)
|
| 383 |
if read['words_checked'] == 0:
|
| 384 |
-
summary += "
|
| 385 |
elif read['contrast_issues'] == 0 and read['small_text_issues'] == 0:
|
| 386 |
summary += "clean, no changes needed\n"
|
| 387 |
else:
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
def compute_readability_score(read):
|
| 112 |
+
if read['words_checked'] == 0:
|
| 113 |
+
return None
|
| 114 |
penalty = 12 * math.sqrt(read['contrast_issues']) + 8 * math.sqrt(read['small_text_issues'])
|
| 115 |
return round(max(0, 100 - penalty), 1)
|
| 116 |
|
| 117 |
|
| 118 |
def compute_overall_grade(focus_score, spread_score, readability_score):
|
| 119 |
+
if readability_score is None:
|
| 120 |
+
total = round((0.55 / 0.75) * focus_score + (0.20 / 0.75) * spread_score)
|
| 121 |
+
else:
|
| 122 |
+
total = round(0.55 * focus_score + 0.20 * spread_score + 0.25 * readability_score)
|
| 123 |
total = max(0, min(100, total))
|
| 124 |
if total >= 75:
|
| 125 |
grade = "Strong"
|
|
|
|
| 131 |
|
| 132 |
|
| 133 |
def explain_grade(focus_score, readability_score, read):
|
| 134 |
+
if readability_score is None:
|
| 135 |
+
if focus_score < 50:
|
| 136 |
+
return "based on attention alone (this design's text couldn't be reliably read, so readability wasn't scored) - mainly because attention is spread out without one clear focal point"
|
| 137 |
+
elif focus_score > 90:
|
| 138 |
+
return "based on attention alone (this design's text couldn't be reliably read, so readability wasn't scored) - attention is very tightly focused on one spot"
|
| 139 |
+
else:
|
| 140 |
+
return "based on attention alone - this design's text couldn't be reliably read, so readability wasn't included"
|
| 141 |
total_issues = read['contrast_issues'] + read['small_text_issues']
|
| 142 |
weighted_focus_deficit = 0.55 * max(0, 100 - focus_score)
|
| 143 |
weighted_read_deficit = 0.25 * max(0, 100 - readability_score)
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
def create_score_chart(focus_score, spread_score, readability_score):
|
| 165 |
+
labels = ["Clear Focal\nPoint", "Attention\nCoverage"]
|
| 166 |
+
values = [focus_score, spread_score]
|
| 167 |
+
if readability_score is not None:
|
| 168 |
+
labels.append("Readability")
|
| 169 |
+
values.append(readability_score)
|
| 170 |
colors = []
|
| 171 |
for v in values:
|
| 172 |
if v >= 75:
|
|
|
|
| 396 |
f"- Readability: "
|
| 397 |
)
|
| 398 |
if read['words_checked'] == 0:
|
| 399 |
+
summary += "couldn't be reliably read on this design (common with heavily stylized or hand-lettered fonts) - not included in the score above\n"
|
| 400 |
elif read['contrast_issues'] == 0 and read['small_text_issues'] == 0:
|
| 401 |
summary += "clean, no changes needed\n"
|
| 402 |
else:
|