""" Postman Testing Guide for GradCAM API Complete instructions for testing all GradCAM endpoints """ # ============================================================================== # POSTMAN SETUP AND TESTING GUIDE FOR GRADCAM API # ============================================================================== POSTMAN_COLLECTION_JSON = ''' { "info": { "name": "GradCAM Deepfake Detection API", "description": "Test collection for GradCAM visualization endpoints", "version": "1.0.0" }, "variable": [ { "key": "base_url", "value": "http://localhost:5000", "type": "string" } ], "item": [ { "name": "1. Test Service Status", "request": { "method": "GET", "header": [], "url": { "raw": "{{base_url}}/api/gradcam/test", "host": ["{{base_url}}"], "path": ["api", "gradcam", "test"] }, "description": "Test if GradCAM service is running and model is loaded" } }, { "name": "2. Get Model Information", "request": { "method": "GET", "header": [], "url": { "raw": "{{base_url}}/api/gradcam/model-info", "host": ["{{base_url}}"], "path": ["api", "gradcam", "model-info"] }, "description": "Get detailed information about GradCAM capabilities and available layers" } }, { "name": "3. Single Image Analysis", "request": { "method": "POST", "header": [], "body": { "mode": "formdata", "formdata": [ { "key": "image", "type": "file", "src": "" }, { "key": "return_image", "value": "true", "type": "text" }, { "key": "layer_name", "value": "", "type": "text" } ] }, "url": { "raw": "{{base_url}}/api/gradcam/analyze", "host": ["{{base_url}}"], "path": ["api", "gradcam", "analyze"] }, "description": "Analyze single image with GradCAM visualization" } }, { "name": "4. Batch Image Analysis", "request": { "method": "POST", "header": [], "body": { "mode": "formdata", "formdata": [ { "key": "images", "type": "file", "src": "" }, { "key": "images", "type": "file", "src": "" }, { "key": "max_images", "value": "5", "type": "text" } ] }, "url": { "raw": "{{base_url}}/api/gradcam/analyze-batch", "host": ["{{base_url}}"], "path": ["api", "gradcam", "analyze-batch"] }, "description": "Batch analysis of multiple images" } }, { "name": "5. Backend Status Check", "request": { "method": "GET", "header": [], "url": { "raw": "{{base_url}}/", "host": ["{{base_url}}"], "path": [""] }, "description": "Check overall backend status and available endpoints" } } ] } ''' # ============================================================================== # STEP-BY-STEP TESTING INSTRUCTIONS # ============================================================================== TESTING_INSTRUCTIONS = """ šŸ“‹ POSTMAN TESTING GUIDE - GradCAM API ==================================== šŸš€ SETUP -------- 1. Start your Flask backend: cd "d:\\SGP\\DeepFake\\Deepfake-Detection\\Webapp\\Model_Load" python app.py 2. Backend should be running on: http://localhost:5000 3. Import Postman Collection: - Copy the JSON collection above - In Postman: Import > Raw Text > Paste JSON > Import šŸ“ TEST SEQUENCE --------------- TEST 1: Service Status Check --------------------------- • Method: GET • URL: http://localhost:5000/api/gradcam/test • Headers: None required • Body: None Expected Response: { "status": "GradCAM Analysis Service Active", "model_loaded": true, "face_detector_ready": true, "memory_optimization": "Enabled", "capabilities": [...], "test_successful": true } āœ… Success: Status 200, test_successful = true āŒ Fail: Status 500, check model loading TEST 2: Model Information ------------------------ • Method: GET • URL: http://localhost:5000/api/gradcam/model-info • Headers: None required • Body: None Expected Response: { "model_name": "XceptionNet with GradCAM", "description": "Visual explanation of deepfake detection...", "capabilities": {...}, "available_layers": [...], "recommended_layers": [...] } āœ… Success: Status 200, layers list populated āŒ Fail: Status 500, model not loaded TEST 3: Single Image Analysis ----------------------------- • Method: POST • URL: http://localhost:5000/api/gradcam/analyze • Headers: None required (auto-detected) Body (form-data): ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ Key │ Type │ Value │ ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤ │ image │ file │ [Select image with face] │ │ return_image │ text │ true │ │ layer_name │ text │ (leave empty for auto-detect) │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ Expected Response: { "success": true, "prediction": { "classification": "DEEPFAKE" or "AUTHENTIC", "is_deepfake": true/false, "confidence": 0.85, "raw_score": 0.7234 }, "face_detection": { "face_found": true, "face_confidence": 0.99, "face_coordinates": {...} }, "gradcam_analysis": { "layer_used": "block14_sepconv1_act", "heatmap_statistics": {...} }, "visualization": { "format": "PNG (base64 encoded)", "data": "iVBORw0KGgoAAAANSUhEUgAA...", "description": "GradCAM visualization..." }, "interpretation": {...}, "metadata": {...} } āœ… Success: Status 200, success = true, visualization data present āŒ Fail: Status 400, no face detected or invalid image TEST 4: Batch Analysis --------------------- • Method: POST • URL: http://localhost:5000/api/gradcam/analyze-batch • Headers: None required Body (form-data): ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ Key │ Type │ Value │ ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤ │ images │ file │ [Select first image] │ │ images │ file │ [Select second image] │ │ images │ file │ [Select more images...] │ │ max_images │ text │ 5 │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ Note: Add multiple 'images' keys for multiple files Expected Response: { "success": true, "batch_summary": { "total_files": 3, "processed_successfully": 2, "failed_files": 1, "deepfake_detected": 1, "authentic_detected": 1, "average_confidence": 0.78 }, "results": [...], "failed_files": [...], "metadata": {...} } āœ… Success: Status 200, batch_summary populated āŒ Fail: Status 400, no valid images provided TEST 5: Backend Compatibility ----------------------------- • Method: GET • URL: http://localhost:5000/ • Headers: None required • Body: None Expected Response: { "status": "ok", "message": "Deepfake Detection API Backend is running", "available_endpoints": { "gradcam_analysis": "/api/gradcam/analyze", "gradcam_batch": "/api/gradcam/analyze-batch", "gradcam_info": "/api/gradcam/model-info", "gradcam_test": "/api/gradcam/test" }, "new_features": { "gradcam_visualization": "Visual explanation of AI decisions" } } āœ… Success: Status 200, gradcam endpoints listed āŒ Fail: Backend not running or integration failed """ # ============================================================================== # COMMON ERROR CODES AND SOLUTIONS # ============================================================================== ERROR_TROUBLESHOOTING = """ šŸ”§ TROUBLESHOOTING GUIDE ======================== ERROR 1: Connection Refused --------------------------- Symptoms: Can't connect to localhost:5000 Solutions: • Ensure Flask app is running: python app.py • Check if port 5000 is available • Verify no firewall blocking • Try: curl http://localhost:5000/ ERROR 2: Model Not Loaded (Status 500) -------------------------------------- Symptoms: test_successful = false, model_loaded = false Solutions: • Check if xceptionnet.keras exists in models/ folder • Verify TensorFlow installation: pip install tensorflow • Check file permissions on model file • Review server logs for detailed error ERROR 3: No Face Detected (Status 400) -------------------------------------- Symptoms: "No face detected" error in analysis Solutions: • Use images with clear, visible faces • Ensure face is well-lit and facing camera • Try different images with larger faces • Check MTCNN installation: pip install mtcnn ERROR 4: Memory Error (Status 500) ---------------------------------- Symptoms: Out of memory during processing Solutions: • Reduce image size before upload (< 2MB recommended) • Reduce batch size (max_images parameter) • Restart Flask server to clear memory • Check available system RAM ERROR 5: Invalid Image Format ----------------------------- Symptoms: "Invalid image file" error Solutions: • Use supported formats: JPG, JPEG, PNG • Ensure file is not corrupted • Check file size (< 10MB recommended) • Try re-saving image in different format ERROR 6: Import Errors (Status 500) ----------------------------------- Symptoms: Module import failures in logs Solutions: • Install missing dependencies: pip install -r requirements.txt • Check virtual environment activation • Verify Python version compatibility (3.7+) • Update packages: pip install --upgrade tensorflow opencv-python PERFORMANCE TIPS: • Use images 800x600 or smaller for faster processing • JPEG format is typically faster than PNG • Batch processing is more efficient for multiple images • Clear browser cache if using web interface """ # ============================================================================== # SAMPLE CURL COMMANDS (Alternative to Postman) # ============================================================================== CURL_EXAMPLES = ''' 🌐 CURL COMMAND EXAMPLES ======================== # Test 1: Service Status curl -X GET http://localhost:5000/api/gradcam/test # Test 2: Model Info curl -X GET http://localhost:5000/api/gradcam/model-info # Test 3: Single Image Analysis curl -X POST http://localhost:5000/api/gradcam/analyze \\ -F "image=@/path/to/your/image.jpg" \\ -F "return_image=true" \\ -F "layer_name=" # Test 4: Batch Analysis curl -X POST http://localhost:5000/api/gradcam/analyze-batch \\ -F "images=@/path/to/image1.jpg" \\ -F "images=@/path/to/image2.jpg" \\ -F "max_images=5" # Test 5: Backend Status curl -X GET http://localhost:5000/ ''' if __name__ == "__main__": print("šŸ“– POSTMAN TESTING GUIDE FOR GRADCAM API") print("="*50) # Save collection to file with open("GradCAM_API_Collection.json", "w") as f: f.write(POSTMAN_COLLECTION_JSON) print("āœ… Postman collection saved to: GradCAM_API_Collection.json") print("\nšŸ“‹ TESTING INSTRUCTIONS:") print(TESTING_INSTRUCTIONS) print("\nšŸ”§ TROUBLESHOOTING:") print(ERROR_TROUBLESHOOTING) print("\n🌐 CURL ALTERNATIVES:") print(CURL_EXAMPLES)