Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,32 +18,6 @@ MODEL_OPTIONS = {
|
|
| 18 |
|
| 19 |
loaded_models = {}
|
| 20 |
|
| 21 |
-
# ---- mobile-safe size limits (aggressive for Safari) ----
|
| 22 |
-
MAX_SIDE = 384
|
| 23 |
-
MAX_PIXELS = 384 * 384
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def safe_resize(image_np):
|
| 27 |
-
"""
|
| 28 |
-
Downscale image to fit within MAX_SIDE and MAX_PIXELS while
|
| 29 |
-
preserving aspect ratio. Works for RGB / RGBA / grayscale.
|
| 30 |
-
"""
|
| 31 |
-
h, w = image_np.shape[:2]
|
| 32 |
-
total = h * w
|
| 33 |
-
|
| 34 |
-
# already small enough
|
| 35 |
-
if max(h, w) <= MAX_SIDE and total <= MAX_PIXELS:
|
| 36 |
-
return image_np
|
| 37 |
-
|
| 38 |
-
# compute scale so BOTH constraints are satisfied
|
| 39 |
-
scale_side = MAX_SIDE / max(h, w)
|
| 40 |
-
scale_pixels = (MAX_PIXELS / total) ** 0.5
|
| 41 |
-
scale = min(scale_side, scale_pixels)
|
| 42 |
-
|
| 43 |
-
new_w = max(1, int(w * scale))
|
| 44 |
-
new_h = max(1, int(h * scale))
|
| 45 |
-
|
| 46 |
-
return cv2.resize(image_np, (new_w, new_h), interpolation=cv2.INTER_AREA)
|
| 47 |
|
| 48 |
|
| 49 |
def extract_region_from_editor(editor_data):
|
|
@@ -291,8 +265,6 @@ def run_segmentation_editor(editor_data, model_choice, min_cell_size, max_cell_s
|
|
| 291 |
if region_np is None:
|
| 292 |
return 0, None, "No image provided.", gr.update(visible=False), None, None, 0.0, gr.update()
|
| 293 |
|
| 294 |
-
# Enforce mobile-safe size limit immediately
|
| 295 |
-
region_np = safe_resize(region_np)
|
| 296 |
|
| 297 |
# Process image format to RGB
|
| 298 |
if len(region_np.shape) == 2:
|
|
|
|
| 18 |
|
| 19 |
loaded_models = {}
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
def extract_region_from_editor(editor_data):
|
|
|
|
| 265 |
if region_np is None:
|
| 266 |
return 0, None, "No image provided.", gr.update(visible=False), None, None, 0.0, gr.update()
|
| 267 |
|
|
|
|
|
|
|
| 268 |
|
| 269 |
# Process image format to RGB
|
| 270 |
if len(region_np.shape) == 2:
|