Spaces:
Sleeping
Sleeping
Update app.py
Browse files19 unmodified lines2021222324252627640 unmodified lines66866967067167267367496 unmodified lines7717727737747757767777787797807 unmodified lines78878979079179279379479519 unmodified linesfrom reportlab.lib.styles import getSampleStyleSheetfrom reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image as RLImage_msi_model = NoneLOGO_PATH = "logo.png"def add_watermark(pil_img, logo_path=LOGO_PATH, scale=0.20, opacity=0.95):640 unmodified linesdef 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]96 unmodified linesresult_image = add_watermark(Image.fromarray(overlay_rgb))chart_image = add_watermark(chart_image, scale=0.26)return result_image, chart_image, summarywith gr.Blocks(title="Design Analyzer") as demo:with gr.Row():with gr.Column():image_input = gr.Image(type="pil", label="Upload design")7 unmodified lineswith gr.Row():pdf_btn = gr.Button("Download PDF Report")pdf_output = gr.File(label="PDF Report")analyze_btn.click(fn=analyze, inputs=[image_input, strength_slider], outputs=[image_output, chart_output, text_output])pdf_btn.click(fn=export_pdf, inputs=[image_output, chart_output, text_output], outputs=pdf_output)gr.Markdown("---\n© 2026 Haan Ilango. All rights reserved. This tool's methodology and design are original work.")demo.launch()19 unmodified lines202122232425262728293031323334353637383940414243444546474849505152535455565758596061640 unmodified lines70270370470570670770896 unmodified lines8058068078088098108118128138148158168178187 unmodified lines82682782882983083183283383483519 unmodified linesfrom reportlab.lib.styles import getSampleStyleSheetfrom reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image as RLImageimport requests_msi_model = NoneLOGO_PATH = "logo.png"COUNTAPI_NAMESPACE = "haanilango-design-analyzer"COUNTAPI_KEY = "images-analyzed"def format_count_badge(count):return (f'<div style="background-color:#1e2761; color:white; text-align:center; 'f'padding:20px; border-radius:8px; margin-bottom:10px;">'f'<div style="font-size:28px; letter-spacing:4px;">★★★★★</div>'f'<div style="font-size:20px; font-weight:bold; margin-top:8px;">{count:,} images were tested</div>'f'</div>')def get_current_count():try:resp = requests.get(f"https://api.countapi.xyz/get/{COUNTAPI_NAMESPACE}/{COUNTAPI_KEY}", timeout=5)if resp.status_code == 200:return resp.json().get("value", 0)except Exception:passreturn 0def increment_count():try:resp = requests.get(f"https://api.countapi.xyz/hit/{COUNTAPI_NAMESPACE}/{COUNTAPI_KEY}", timeout=5)if resp.status_code == 200:return resp.json().get("value", None)except Exception:passreturn Nonedef add_watermark(pil_img, logo_path=LOGO_PATH, scale=0.20, opacity=0.95):640 unmodified linesdef analyze(pil_image, overlay_strength):if pil_image is None:return None, None, "Upload an image first.", gr.update()pil_rgb = flatten_transparency(pil_image)img_bgr = cv2.cvtColor(np.array(pil_rgb), cv2.COLOR_RGB2BGR)h, w = img_bgr.shape[:2]96 unmodified linesresult_image = add_watermark(Image.fromarray(overlay_rgb))chart_image = add_watermark(chart_image, scale=0.26)new_count = increment_count()badge_html = format_count_badge(new_count) if new_count is not None else gr.update()return result_image, chart_image, summary, badge_htmlwith gr.Blocks(title="Design Analyzer") as demo:count_display = gr.HTML(format_count_badge(0))with gr.Row():with gr.Column():image_input = gr.Image(type="pil", label="Upload design")7 unmodified lineswith gr.Row():pdf_btn = gr.Button("Download PDF Report")pdf_output = gr.File(label="PDF Report")analyze_btn.click(fn=analyze, inputs=[image_input, strength_slider],outputs=[image_output, chart_output, text_output, count_display])pdf_btn.click(fn=export_pdf, inputs=[image_output, chart_output, text_output], outputs=pdf_output)demo.load(fn=lambda: format_count_badge(get_current_count()), outputs=count_display)gr.Markdown("---\n© 2026 Haan Ilango. All rights reserved. This tool's methodology and design are original work.")demo.launch()
app.py+43-3