Spaces:
Sleeping
Sleeping
Update app.py
Browse files21 unmodified lines2223242526272829303132671 unmodified lines70470570670770870971071171271371471571671771871972072172272372472572672721 unmodified lines
import requests
# Raise Pillow's decompression-bomb limit so large print-resolution files# (banners, posters) aren't rejected outright. 400 million pixels covers# very large print files while still blocking truly absurd inputs.Image.MAX_IMAGE_PIXELS = 400_000_000
_msi_model = NoneLOGO_PATH = "logo.png"COUNTAPI_BASE = "https://countapi.mileshilliard.com/api/v1"671 unmodified lines return pil_image.convert("RGB")
def downscale_if_huge(pil_image, max_dim=3000): # Large print files (banners, posters) can be tens of megapixels. # The heatmap and PDF don't need print resolution, and running # saliency + OCR on a huge image would be slow on CPU-only hardware, # so shrink anything oversized before analysis. w, h = pil_image.size if max(w, h) <= max_dim: return pil_image scale = max_dim / max(w, h) new_size = (max(1, int(w * scale)), max(1, int(h * scale))) return pil_image.resize(new_size, Image.LANCZOS)
def 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) pil_rgb = downscale_if_huge(pil_rgb) img_bgr = cv2.cvtColor(np.array(pil_rgb), cv2.COLOR_RGB2BGR) h, w = img_bgr.shape[:2]
app.py+19