fix: cache issue for first example load
Browse files
app.py
CHANGED
|
@@ -449,8 +449,17 @@ def run_identification(
|
|
| 449 |
else selected_body_parts
|
| 450 |
)
|
| 451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
# Check cache for example images (v2.0 cache supports filtering)
|
| 453 |
-
if example_path and
|
| 454 |
logger.info(f"Cache hit for {example_path} with {extractor}")
|
| 455 |
if filter_locations or filter_body_parts_parsed:
|
| 456 |
logger.info(
|
|
@@ -1546,17 +1555,22 @@ Click a row to view detailed feature matching visualization and all reference im
|
|
| 1546 |
|
| 1547 |
# Load first example image on startup
|
| 1548 |
def load_first_example():
|
| 1549 |
-
"""Load the first example image when the app starts.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1550 |
if example_images:
|
| 1551 |
try:
|
| 1552 |
first_image = Image.open(example_images[0])
|
| 1553 |
-
|
|
|
|
| 1554 |
except Exception as e:
|
| 1555 |
logger.error(f"Error loading first example image: {e}")
|
| 1556 |
-
return None
|
| 1557 |
-
return None
|
| 1558 |
|
| 1559 |
-
app.load(fn=load_first_example, outputs=[image_input])
|
| 1560 |
|
| 1561 |
return app
|
| 1562 |
|
|
|
|
| 449 |
else selected_body_parts
|
| 450 |
)
|
| 451 |
|
| 452 |
+
# Debug logging for cache check
|
| 453 |
+
logger.info(f"Cache check: example_path={example_path}, extractor={extractor}")
|
| 454 |
+
if example_path:
|
| 455 |
+
cache_exists = is_cached(example_path, extractor)
|
| 456 |
+
logger.info(f"is_cached() returned: {cache_exists}")
|
| 457 |
+
else:
|
| 458 |
+
cache_exists = False
|
| 459 |
+
logger.info("No example_path provided, skipping cache")
|
| 460 |
+
|
| 461 |
# Check cache for example images (v2.0 cache supports filtering)
|
| 462 |
+
if example_path and cache_exists:
|
| 463 |
logger.info(f"Cache hit for {example_path} with {extractor}")
|
| 464 |
if filter_locations or filter_body_parts_parsed:
|
| 465 |
logger.info(
|
|
|
|
| 1555 |
|
| 1556 |
# Load first example image on startup
|
| 1557 |
def load_first_example():
|
| 1558 |
+
"""Load the first example image when the app starts.
|
| 1559 |
+
|
| 1560 |
+
Returns both the image AND the path so the cache can be used
|
| 1561 |
+
when the user clicks Identify without selecting a new example.
|
| 1562 |
+
"""
|
| 1563 |
if example_images:
|
| 1564 |
try:
|
| 1565 |
first_image = Image.open(example_images[0])
|
| 1566 |
+
first_path = str(example_images[0])
|
| 1567 |
+
return first_image, first_path
|
| 1568 |
except Exception as e:
|
| 1569 |
logger.error(f"Error loading first example image: {e}")
|
| 1570 |
+
return None, None
|
| 1571 |
+
return None, None
|
| 1572 |
|
| 1573 |
+
app.load(fn=load_first_example, outputs=[image_input, selected_example_state])
|
| 1574 |
|
| 1575 |
return app
|
| 1576 |
|