Deep_fake_Model_load / docs /postman_testing_guide.py
Jay9115's picture
full_commit
eeeea78
Raw History Blame Contribute Delete
12.7 kB
"""
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)