Spaces:
Sleeping
Sleeping
Update app.py
Browse files19 unmodified lines202122232425262728293031323334353637383940414243444546474849505152535455565758596061640 unmodified lines70270370467170570670770896 unmodified lines8058068078088098107748118128138148158168178187 unmodified lines82682782879182983083183283383483519 unmodified linesfrom reportlab.lib.styles import getSampleStyleSheetfrom reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image as RLImage
import 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: pass return 0
def 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: pass return None
def add_watermark(pil_img, logo_path=LOGO_PATH, scale=0.20, opacity=0.95):640 unmodified lines
def analyze(pil_image, overlay_strength): if pil_image is None: return None, None, "Upload an image first." 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 lines result_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 return result_image, chart_image, summary, badge_html
with 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 lines with 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]) 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