Spaces:
Sleeping
Sleeping
Update app.py
Browse files170 unmodified lines1711721731741741751761771781791761801811821833 unmodified lines187188189190191186192193194195453 unmodified lines6496506516526536546556566576586596606616626636496646656666675 unmodified lines673674675661676677678679170 unmodified lines return total, grade
def explain_grade(focus_score, readability_score, read):def explain_grade(focus_score, spread_score, readability_score, read): coverage_score = coverage_grade_score(spread_score) weighted_coverage_deficit = 0.20 * max(0, 100 - coverage_score) if readability_score is None: if weighted_coverage_deficit > 0.55 * max(0, 100 - focus_score): return "based on attention alone (this design's text couldn't be reliably read, so readability wasn't scored) - mainly because attention is spread too widely without settling anywhere" if focus_score < 50: elif focus_score < 50: 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" elif focus_score > 90: 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"3 unmodified lines weighted_focus_deficit = 0.55 * max(0, 100 - focus_score) weighted_read_deficit = 0.25 * max(0, 100 - readability_score)
if weighted_coverage_deficit > weighted_focus_deficit and weighted_coverage_deficit > weighted_read_deficit: return "mainly because attention is spread too widely across the design without settling anywhere" if weighted_read_deficit >= weighted_focus_deficit and total_issues > 0: elif weighted_read_deficit >= weighted_focus_deficit and total_issues > 0: return "mainly due to text readability - some text is harder to read than ideal" elif focus_score < 50: return "mainly because attention is spread out, without one clear focal point"453 unmodified lines return img
def flatten_transparency(pil_image): if pil_image.mode in ("RGBA", "LA") or (pil_image.mode == "P" and "transparency" in pil_image.info): rgba = pil_image.convert("RGBA") background = Image.new("RGB", rgba.size, (255, 255, 255)) background.paste(rgba, mask=rgba.split()[-1]) return background return pil_image.convert("RGB")
def analyze(pil_image, overlay_strength): if pil_image is None: return None, None, "Upload an image first." pil_rgb = pil_image.convert("RGB") pil_rgb = flatten_transparency(pil_image) img_bgr = cv2.cvtColor(np.array(pil_rgb), cv2.COLOR_RGB2BGR) h, w = img_bgr.shape[:2]
5 unmodified lines read = analyze_readability(pil_rgb) readability_score = compute_readability_score(read) total_score, grade = compute_overall_grade(scores['focus_score'], scores['spread_score'], readability_score) grade_reason = explain_grade(scores['focus_score'], readability_score, read) grade_reason = explain_grade(scores['focus_score'], scores['spread_score'], readability_score, read) tips = generate_recommendations(saliency_map, scores, read, h, w) hierarchy_result = compute_hierarchy(read.get('text_sizes', [])) balance_score = compute_balance(saliency_map)app.py+20-5