feat: add image quality validation before disease diagnosis#70
feat: add image quality validation before disease diagnosis#70stefrinpaul-curious wants to merge 3 commits into
Conversation
|
@stefrinpaul-curious is attempting to deploy a commit to the karan3431's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
🎉 Thanks for your contribution, @stefrinpaul-curious! Please make sure CI passes and the checklist in the PR template is complete. A maintainer will review this soon. — The AgroNavis team |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds backend image-quality validation before diagnosis, returns a quality-error response when validation fails, updates the frontend to render that state, and changes farm creation to require an existing farmer profile. ChangesImage Quality Validation Pipeline
Farm Creation Farmer Validation Fix
Sequence Diagram(s)sequenceDiagram
participant User
participant CropScanTab
participant run_inference
participant validate_image_quality
participant ResNet
User->>CropScanTab: Upload crop image
CropScanTab->>run_inference: POST image
run_inference->>validate_image_quality: validate(image)
validate_image_quality-->>run_inference: {valid, quality_score, blur_score, brightness}
alt image invalid
run_inference-->>CropScanTab: PredictionResponse(is_quality_error=true)
CropScanTab-->>User: Show quality badge and fix guidance
else image valid
run_inference->>ResNet: classify(image)
ResNet-->>run_inference: prediction
run_inference-->>CropScanTab: PredictionResponse(is_quality_error=false)
CropScanTab-->>User: Show diagnosis result
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/image_validation.py`:
- Around line 1-2: The cv2 module imported in image_validation.py is not
declared as a runtime dependency in the requirements file. Add `opencv-python`
to the backend requirements file to ensure the dependency is installed when the
API starts. For headless deployments without GUI capabilities, use
`opencv-python-headless` instead, as it is lighter weight and sufficient for
image processing operations without display functionality.
In `@frontend/src/styles/CropScan.module.css`:
- Around line 232-254: Rename the CSS class selectors from camelCase to
kebab-case format: change .healthyBadge to .healthy-badge, .diseaseBadge to
.disease-badge, and .qualityBadge to .quality-badge. Add empty lines before each
rule definition to satisfy the rule-empty-line-before lint check. Update the
corresponding TypeScript module lookups in CropScanTab.tsx to reference the new
kebab-case class names instead of the camelCase versions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 48d3a352-4e7c-4324-b407-4c0b580ec3bc
📒 Files selected for processing (5)
backend/image_validation.pybackend/main.pyfrontend/src/components/CropScanTab.tsxfrontend/src/styles/CropScan.module.cssfrontend/src/utils/cropScanApi.ts
| .healthyBadge { | ||
| background: #16a34a; | ||
| color: white; | ||
| padding: 8px 12px; | ||
| border-radius: 8px; | ||
| font-weight: 600; | ||
| } | ||
|
|
||
| .diseaseBadge { | ||
| background: #dc2626; | ||
| color: white; | ||
| padding: 8px 12px; | ||
| border-radius: 8px; | ||
| font-weight: 600; | ||
| } | ||
|
|
||
| .qualityBadge { | ||
| background: #ea580c; | ||
| color: white; | ||
| padding: 8px 12px; | ||
| border-radius: 8px; | ||
| font-weight: 600; | ||
| } |
There was a problem hiding this comment.
Fix stylelint violations for new badge selectors.
The new rules currently violate configured lint checks (rule-empty-line-before and selector-class-pattern expecting kebab-case). Please rename selectors to kebab-case and add the required spacing (and update TS module lookups accordingly).
💡 Example fix pattern
-.healthyBadge {
+.healthy-badge {
...
}
-.diseaseBadge {
+.disease-badge {
...
}
-.qualityBadge {
+.quality-badge {
...
}And in frontend/src/components/CropScanTab.tsx:
-? styles.qualityBadge
+? styles['quality-badge']🧰 Tools
🪛 Stylelint (17.13.0)
[error] 232-238: Expected empty line before rule (rule-empty-line-before)
(rule-empty-line-before)
[error] 232-232: Expected class selector ".healthyBadge" to be kebab-case (selector-class-pattern)
(selector-class-pattern)
[error] 240-240: Expected class selector ".diseaseBadge" to be kebab-case (selector-class-pattern)
(selector-class-pattern)
[error] 248-248: Expected class selector ".qualityBadge" to be kebab-case (selector-class-pattern)
(selector-class-pattern)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@frontend/src/styles/CropScan.module.css` around lines 232 - 254, Rename the
CSS class selectors from camelCase to kebab-case format: change .healthyBadge to
.healthy-badge, .diseaseBadge to .disease-badge, and .qualityBadge to
.quality-badge. Add empty lines before each rule definition to satisfy the
rule-empty-line-before lint check. Update the corresponding TypeScript module
lookups in CropScanTab.tsx to reference the new kebab-case class names instead
of the camelCase versions.
Source: Linters/SAST tools
stefrinpaul-curious
left a comment
There was a problem hiding this comment.
I have reviewed everything and it is completely fine
Summary
Adds image quality validation before crop disease diagnosis to prevent low-quality images from being processed by the AI model. Images with insufficient resolution, excessive blur, or poor lighting are rejected with user-friendly feedback.
Related Issue
Closes #63
Changes
image_validation.pyutility moduleTesting
Local Testing Steps
Checklist
.envvalues are committedSummary by CodeRabbit