Spaces:
Sleeping
Sleeping
AMontiB commited on
Commit ·
0e73e98
1
Parent(s): 7c57ed0
update
Browse files- shadows.py +9 -3
shadows.py
CHANGED
|
@@ -307,7 +307,10 @@ def reset_all(image, current_mode, current_points, y_lines, r_lines, y_pairs, r_
|
|
| 307 |
else:
|
| 308 |
# Fallback: use current image (might have overlays, but better than nothing)
|
| 309 |
base_pil = Image.fromarray(image) if not isinstance(image, Image.Image) else image
|
| 310 |
-
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
# ------------------------------ Build Blocks ------------------------------
|
| 313 |
|
|
@@ -334,14 +337,17 @@ def build_gradio_interface():
|
|
| 334 |
r_pairs = gr.State([])
|
| 335 |
original_image = gr.State(None) # Store original base image without overlays
|
| 336 |
|
| 337 |
-
# Store original image when uploaded
|
| 338 |
def store_original(img, orig):
|
| 339 |
"""Store the original image when a new image is uploaded."""
|
| 340 |
if img is not None:
|
|
|
|
|
|
|
|
|
|
| 341 |
return img # Store the new image as original
|
| 342 |
return orig # Keep existing original if no new image
|
| 343 |
|
| 344 |
-
img_in.
|
| 345 |
|
| 346 |
# link buttons to mode change
|
| 347 |
start_y.click(on_mode_change, inputs=[gr.State("yellow"), img_in, current_mode, current_points, y_lines, r_lines, y_pairs, r_pairs],
|
|
|
|
| 307 |
else:
|
| 308 |
# Fallback: use current image (might have overlays, but better than nothing)
|
| 309 |
base_pil = Image.fromarray(image) if not isinstance(image, Image.Image) else image
|
| 310 |
+
|
| 311 |
+
# Convert PIL image to numpy array for Gradio (since type="numpy")
|
| 312 |
+
base_np = np.array(base_pil.convert("RGB"))
|
| 313 |
+
return base_np, None, [], [], [], [], []
|
| 314 |
|
| 315 |
# ------------------------------ Build Blocks ------------------------------
|
| 316 |
|
|
|
|
| 337 |
r_pairs = gr.State([])
|
| 338 |
original_image = gr.State(None) # Store original base image without overlays
|
| 339 |
|
| 340 |
+
# Store original image when uploaded (not when programmatically changed)
|
| 341 |
def store_original(img, orig):
|
| 342 |
"""Store the original image when a new image is uploaded."""
|
| 343 |
if img is not None:
|
| 344 |
+
# Make a copy to ensure it doesn't get modified
|
| 345 |
+
if isinstance(img, np.ndarray):
|
| 346 |
+
return img.copy()
|
| 347 |
return img # Store the new image as original
|
| 348 |
return orig # Keep existing original if no new image
|
| 349 |
|
| 350 |
+
img_in.upload(store_original, inputs=[img_in, original_image], outputs=[original_image])
|
| 351 |
|
| 352 |
# link buttons to mode change
|
| 353 |
start_y.click(on_mode_change, inputs=[gr.State("yellow"), img_in, current_mode, current_points, y_lines, r_lines, y_pairs, r_pairs],
|