HaanIlango commited on
Commit
493f2dd
·
verified ·
1 Parent(s): fdff9a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -20
app.py CHANGED
@@ -20,8 +20,42 @@ from reportlab.lib.units import inch
20
  from reportlab.lib.styles import getSampleStyleSheet
21
  from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image as RLImage
22
 
 
 
23
  _msi_model = None
24
  LOGO_PATH = "logo.png"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
 
27
  def add_watermark(pil_img, logo_path=LOGO_PATH, scale=0.20, opacity=0.95):
@@ -668,7 +702,7 @@ def flatten_transparency(pil_image):
668
 
669
  def analyze(pil_image, overlay_strength):
670
  if pil_image is None:
671
- return None, None, "Upload an image first."
672
  pil_rgb = flatten_transparency(pil_image)
673
  img_bgr = cv2.cvtColor(np.array(pil_rgb), cv2.COLOR_RGB2BGR)
674
  h, w = img_bgr.shape[:2]
@@ -771,25 +805,11 @@ def analyze(pil_image, overlay_strength):
771
  result_image = add_watermark(Image.fromarray(overlay_rgb))
772
  chart_image = add_watermark(chart_image, scale=0.26)
773
 
774
- return result_image, chart_image, summary
 
 
 
775
 
776
 
777
  with gr.Blocks(title="Design Analyzer") as demo:
778
- with gr.Row():
779
- with gr.Column():
780
- image_input = gr.Image(type="pil", label="Upload design")
781
- strength_slider = gr.Slider(0.1, 0.8, value=0.45, step=0.05, label="Heatmap overlay strength")
782
- analyze_btn = gr.Button("Analyze", variant="primary")
783
- with gr.Column():
784
- image_output = gr.Image(label="Heatmap result", interactive=False)
785
- chart_output = gr.Image(label="Scores at a glance", interactive=False)
786
- with gr.Row():
787
- text_output = gr.Markdown()
788
- with gr.Row():
789
- pdf_btn = gr.Button("Download PDF Report")
790
- pdf_output = gr.File(label="PDF Report")
791
- analyze_btn.click(fn=analyze, inputs=[image_input, strength_slider], outputs=[image_output, chart_output, text_output])
792
- pdf_btn.click(fn=export_pdf, inputs=[image_output, chart_output, text_output], outputs=pdf_output)
793
- gr.Markdown("---\n© 2026 Haan Ilango. All rights reserved. This tool's methodology and design are original work.")
794
-
795
- demo.launch()
 
20
  from reportlab.lib.styles import getSampleStyleSheet
21
  from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image as RLImage
22
 
23
+ import requests
24
+
25
  _msi_model = None
26
  LOGO_PATH = "logo.png"
27
+ COUNTAPI_NAMESPACE = "haanilango-design-analyzer"
28
+ COUNTAPI_KEY = "images-analyzed"
29
+
30
+
31
+ def format_count_badge(count):
32
+ return (
33
+ f'<div style="background-color:#1e2761; color:white; text-align:center; '
34
+ f'padding:20px; border-radius:8px; margin-bottom:10px;">'
35
+ f'<div style="font-size:28px; letter-spacing:4px;">&#9733;&#9733;&#9733;&#9733;&#9733;</div>'
36
+ f'<div style="font-size:20px; font-weight:bold; margin-top:8px;">{count:,} images were tested</div>'
37
+ f'</div>'
38
+ )
39
+
40
+
41
+ def get_current_count():
42
+ try:
43
+ resp = requests.get(f"https://api.countapi.xyz/get/{COUNTAPI_NAMESPACE}/{COUNTAPI_KEY}", timeout=5)
44
+ if resp.status_code == 200:
45
+ return resp.json().get("value", 0)
46
+ except Exception:
47
+ pass
48
+ return 0
49
+
50
+
51
+ def increment_count():
52
+ try:
53
+ resp = requests.get(f"https://api.countapi.xyz/hit/{COUNTAPI_NAMESPACE}/{COUNTAPI_KEY}", timeout=5)
54
+ if resp.status_code == 200:
55
+ return resp.json().get("value", None)
56
+ except Exception:
57
+ pass
58
+ return None
59
 
60
 
61
  def add_watermark(pil_img, logo_path=LOGO_PATH, scale=0.20, opacity=0.95):
 
702
 
703
  def analyze(pil_image, overlay_strength):
704
  if pil_image is None:
705
+ return None, None, "Upload an image first.", gr.update()
706
  pil_rgb = flatten_transparency(pil_image)
707
  img_bgr = cv2.cvtColor(np.array(pil_rgb), cv2.COLOR_RGB2BGR)
708
  h, w = img_bgr.shape[:2]
 
805
  result_image = add_watermark(Image.fromarray(overlay_rgb))
806
  chart_image = add_watermark(chart_image, scale=0.26)
807
 
808
+ new_count = increment_count()
809
+ badge_html = format_count_badge(new_count) if new_count is not None else gr.update()
810
+
811
+ return result_image, chart_image, summary, badge_html
812
 
813
 
814
  with gr.Blocks(title="Design Analyzer") as demo:
815
+ count_display = gr.HTML(format_count_badge(0