"""Input size limits for the Space. The Space is one container on shared CPU hardware serving every visitor at once, so a large raster is not just slow for its uploader: it occupies the CPU and the memory that everyone else's request needs. The QGIS plugin has no equivalent limit because it runs on the user's own desktop, which is exactly what the message below points at. """ # Above this, the run is allowed but the user is warned and pointed at the plugin. SOFT_LIMIT_MP = 4.0 # Above this the container is likely to be killed before the run finishes. HARD_LIMIT_MP = 50.0 LOCAL_USE_NOTE = ( "Large rasters: run this on your own machine, with no size limit — either the " "[FraXtex QGIS plugin](https://gitlab.com/ayoubft/qfraxtex) or " "`git clone https://huggingface.co/spaces/ayoubft/fractex2d && " "pip install -r requirements.txt && python app.py`." ) def megapixels(height, width): return (height * width) / 1e6 def check_size(height, width, feedback): """Warn past the soft limit, abort past the hard one. Raises `FatalError` via `feedback.reportError` when the raster is large enough that the run would most likely die partway through anyway. """ mp = megapixels(height, width) if mp > HARD_LIMIT_MP: feedback.reportError( f"Input is {mp:.1f} MP ({width}x{height}), above this Space's " f"{HARD_LIMIT_MP:.0f} MP limit. A raster this size exhausts the shared " f"container before the run finishes.\n\n{LOCAL_USE_NOTE}", fatalError=True, ) elif mp > SOFT_LIMIT_MP: feedback.pushWarning( f"Input is {mp:.1f} MP ({width}x{height}). Above ~{SOFT_LIMIT_MP:.0f} MP " "this shared CPU Space gets slow, and the request may time out before it " f"returns.\n\n{LOCAL_USE_NOTE}" ) return mp