Feat: Add MRI upload validation and safer preprocessing handling - #25
Feat: Add MRI upload validation and safer preprocessing handling#25Sujan075 wants to merge 6 commits into
Conversation
|
I’ve completed the implementation for Issue #14 — “Add MRI Upload Validation & Better Error Handling for Invalid Medical Images”. Implemented Improvements
Validation & TestingTested scenarios include:
All tests are passing successfully. This PR keeps the changes scoped specifically to upload validation and inference stability without modifying unrelated training/model logic. Looking forward to your review and feedback. Thanks! |
|
@Sujan075 show me before / after test logs and changes. |
|
Image 1:
Image 2:
Image 3:
Hey @Brijeshthummar02, |
|
@Sujan075 i am still not able to figure out entire sequential validation pipeline, explain me in clean sketch how you did it with what was there earlier. also try to clean up ai code a bit. it doesn't show multiple implementations you have mentioned. |
…xception - Catch RequestEntityTooLarge inside predict() try/except so oversized uploads return structured JSON 413 instead of falling through to 500 - Re-raise HTTPException in handle_exception() so registered numeric error handlers (413, 404, 500) are not shadowed by the catch-all Found during validation evidence run for Issue Brijeshthummar02#14.
- Simplify app.py validation to pure sequential 10-step flow - Move image loading logic from app.py to validators.py - Add validate_and_load_image() to consolidate OpenCV/PIL loading - Remove verbose AI-style comments throughout validators.py - Keep all behavior and API responses identical - All 25 unit tests and 7 integration scenarios still pass Addresses maintainer feedback about mixed approaches and confusing flow.
|
I cleaned up and simplified the validation flow to make the sequential pipeline clearer and remove mixed validation approaches. Earlier FlowThe previous implementation had:
This made the upload pipeline harder to follow during review. Refactored Sequential Validation FlowCurrent flow is now: Cleanup Done
Validation Status
The goal of this cleanup was to make the pipeline easier to review and maintain without changing functionality. |
|
have you added this to our existing dashboard on main web? |
|
Hii @Brijeshthummar02, Yess, So the current dashboard/frontend now uses:
The changes were not implemented as isolated utility checks — they are part of the active inference upload pipeline used by the existing web interface. I also verified this through runtime testing from the actual prediction flow while validating the integration scenarios. |
|
resolve conflict |
|
I've addressed the review feedback:
Please let me know if there are any other changes you'd like me to make. Thanks! |



closes#14 — Add MRI Upload Validation & Better Error Handling for Invalid Medical Images
Overview
This PR improves the safety and stability of the MRI upload and preprocessing pipeline by introducing layered validation, safer preprocessing checks, and standardized API error handling.
The goal was to prevent invalid or corrupted uploads from reaching inference while keeping the Flask API stable and user-friendly during failures.
What Changed
Added
validators.pyCreated a dedicated validation module to centralize upload and preprocessing validation logic.
Implemented:
ValidationErrorvalidate_file_present()validate_file_extension()validate_file_size()validate_mime_type()validate_image_loadable()validate_tensor_shape()Validation now combines:
This prevents invalid or corrupted files from reaching preprocessing or inference.
Hardened
/api/predictpipeline inapp.pyReworked the upload flow into a sequential validation pipeline:
All failure paths now return structured JSON responses instead of silent failures or raw exceptions.
Improved Error Handling & Logging
except:blocks with explicit exception handling and loggingExample response format:
{ "error": true, "code": "INVALID_MIME", "message": "File content does not match a valid MRI image format" }Added Validation Tests
Expanded
test_tumor_detection.pywith validation-focused unit tests covering:All tests pass successfully.
Environment Configuration
Added configurable upload limit support via:
Flask upload limits and validator limits now stay synchronized.
Testing
Verified with:
pytest.txt -> .jpgvalidationResult:
Outcome
This PR improves:
while keeping the implementation scoped specifically to the inference upload pipeline.