From da59c00f5adfb2cbb5661a866d1055e489488132 Mon Sep 17 00:00:00 2001 From: Aherobo Ovie Victor Date: Fri, 11 Jul 2025 22:49:26 +0100 Subject: [PATCH] Change hardcoded test image to no-memory image to demonstrate dynamic messaging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Changed Test Image: - Updated HARDCODED_IMAGE_PATH from 'training/memory/out1.png' to 'training/no_memory/out1.png' - Now uses an image without memory modules for testing - Demonstrates the dynamic '❌ No memory modules' message ✅ Dynamic Behavior: - Run All Tests will now show '❌ No memory modules' instead of '✅ Found 2 memory modules' - Same JavaScript logic, different result based on actual detection - No frontend changes needed - purely backend image swap ✅ Testing Both Scenarios: - Hardcoded test: Shows '❌ No memory modules' (no memory image) - Custom upload: Shows '✅ Found X memory modules' or '❌ No memory modules' based on uploaded image - Perfect demonstration of dynamic messaging system This change allows you to see the '❌ No memory modules' message in Run All Tests results. --- main.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index b878140..797b7ab 100644 --- a/main.py +++ b/main.py @@ -37,7 +37,7 @@ MODEL_PATH = 'runs/detect/memory_module_detection/weights/best.pt' detector = MemoryModuleDetector(MODEL_PATH) # Hardcoded test image path -HARDCODED_IMAGE_PATH = 'training/memory/out1.png' +HARDCODED_IMAGE_PATH = 'training/no_memory/out1.png' def allowed_file(filename): """Check if file extension is allowed.""" @@ -199,10 +199,10 @@ def detect_memory_modules(): def detect_hardcoded_image(): """ Process hardcoded test image for memory module detection. - + Optional query parameters: - - confidence: confidence threshold (default: 0.5) - + - confidence: confidence threshold (default: 0.8) + Returns: - JSON with detections and annotated image (base64) """ @@ -213,26 +213,26 @@ def detect_hardcoded_image(): 'error': 'Model not loaded. Please train the model first.', 'success': False }), 500 - + # Check if hardcoded image exists if not os.path.exists(HARDCODED_IMAGE_PATH): return jsonify({ 'error': f'Hardcoded test image not found at {HARDCODED_IMAGE_PATH}', 'success': False }), 404 - + # Get confidence threshold from query parameters (default 80%) conf_threshold = float(request.args.get('confidence', 0.8)) - + # Run detection detections, annotated_image = detector.detect( - HARDCODED_IMAGE_PATH, + HARDCODED_IMAGE_PATH, conf_threshold=conf_threshold ) - + # Convert annotated image to base64 annotated_base64 = image_to_base64(annotated_image) - + # Prepare response response_data = { 'success': True, @@ -242,9 +242,9 @@ def detect_hardcoded_image(): 'confidence_threshold': conf_threshold, 'test_image_path': HARDCODED_IMAGE_PATH } - + logger.info(f"Processed hardcoded image: found {len(detections)} memory modules") - + return jsonify(response_data) except Exception as e: