Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,14 +18,19 @@ def resize_image(img, max_height=500):
|
|
| 18 |
img = img.resize((new_width, max_height), resample=Image.Resampling.LANCZOS)
|
| 19 |
return img
|
| 20 |
|
| 21 |
-
# --- Custom Cropper
|
| 22 |
def custom_cropper(image, key="canvas_crop"):
|
| 23 |
st.markdown("🖍️ Draw a rectangle over the area you want to crop.")
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
canvas_result = st_canvas(
|
| 31 |
fill_color="rgba(255, 165, 0, 0.3)",
|
|
|
|
| 18 |
img = img.resize((new_width, max_height), resample=Image.Resampling.LANCZOS)
|
| 19 |
return img
|
| 20 |
|
| 21 |
+
# --- Final Safe Custom Cropper ---
|
| 22 |
def custom_cropper(image, key="canvas_crop"):
|
| 23 |
st.markdown("🖍️ Draw a rectangle over the area you want to crop.")
|
| 24 |
|
| 25 |
+
# ✅ Safe conversion to array (avoids ValueError)
|
| 26 |
+
background_array = None
|
| 27 |
+
if image is not None:
|
| 28 |
+
try:
|
| 29 |
+
arr = np.array(image)
|
| 30 |
+
if isinstance(arr, np.ndarray) and arr.size > 0:
|
| 31 |
+
background_array = arr
|
| 32 |
+
except Exception:
|
| 33 |
+
background_array = None
|
| 34 |
|
| 35 |
canvas_result = st_canvas(
|
| 36 |
fill_color="rgba(255, 165, 0, 0.3)",
|