Spaces:
Sleeping
Sleeping
Update app.py
Browse files170 unmodified lines1711721731741751761771781793 unmodified lines183184185186187188189453 unmodified lines6436446456466476486496506516525 unmodified lines658659660661662663664170 unmodified linesreturn total, gradedef explain_grade(focus_score, readability_score, read):if readability_score is None:if 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 linesweighted_focus_deficit = 0.55 * max(0, 100 - focus_score)weighted_read_deficit = 0.25 * max(0, 100 - readability_score)if 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 linesreturn imgdef analyze(pil_image, overlay_strength):if pil_image is None:return None, None, "Upload an image first."pil_rgb = pil_image.convert("RGB")img_bgr = cv2.cvtColor(np.array(pil_rgb), cv2.COLOR_RGB2BGR)h, w = img_bgr.shape[:2]5 unmodified linesread = 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)tips = generate_recommendations(saliency_map, scores, read, h, w)hierarchy_result = compute_hierarchy(read.get('text_sizes', []))balance_score = compute_balance(saliency_map)170 unmodified lines1711721731741751761771781791801811821833 unmodified lines187188189190191192193194195453 unmodified lines6496506516526536546556566576586596606616626636646656666675 unmodified lines673674675676677678679170 unmodified linesreturn total, gradedef 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"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 linesweighted_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"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 linesreturn imgdef 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 backgroundreturn pil_image.convert("RGB")def analyze(pil_image, overlay_strength):if pil_image is None:return None, None, "Upload an image first."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 linesread = 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'], 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