itsluckysharma01 commited on
Commit
fb24e2a
·
verified ·
1 Parent(s): b5f303c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +888 -874
README.md CHANGED
@@ -1,874 +1,888 @@
1
- # 🥔 Potato Skin Disease Detection Using Deep Learning
2
-
3
- [![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/)
4
- [![TensorFlow](https://img.shields.io/badge/TensorFlow-2.x-orange.svg)](https://tensorflow.org/)
5
- [![Keras](https://img.shields.io/badge/Keras-2.x-red.svg)](https://keras.io/)
6
- [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
7
-
8
- > 🔬 An AI-powered computer vision system for detecting and classifying potato skin diseases using deep learning techniques.
9
-
10
- ## 📋 Table of Contents
11
-
12
- - [🎯 Project Overview](#-project-overview)
13
- - [🌟 Features](#-features)
14
- - [📊 Dataset](#-dataset)
15
- - [🚀 Getting Started](#-getting-started)
16
- - [💻 Usage](#-usage)
17
- - [🏗️ Model Architecture](#-model-architecture)
18
- - [📈 Results](#-results)
19
- - [🚀 Next Steps](#-Next-Steps)
20
- - [📄 License](#-license)
21
-
22
- ## 🎯 Project Overview
23
-
24
- This project implements a **Convolutional Neural Network (CNN)** using TensorFlow/Keras to automatically detect and classify potato skin diseases from digital images. The system can identify three main categories:
25
-
26
- - 🍃 **Healthy Potatoes**
27
- - 🦠 **Early Blight Disease**
28
- - 🍄 **Late Blight Disease**
29
-
30
- ### 🎥 Demo
31
-
32
- <details>
33
- <summary>Click to see sample predictions</summary>
34
-
35
- ```
36
- Input: potato_image.jpg
37
- Output: "Early Blight Disease" (Confidence: 94.2%)
38
- ```
39
-
40
- </details>
41
-
42
- ## 🌟 Features
43
-
44
- - **Multi-class Classification**: Detects 3 types of potato conditions
45
- - ✅ **Data Augmentation**: Improves model robustness with image transformations
46
- - ✅ **Interactive Visualization**: Displays sample images with predictions
47
- - **Optimized Performance**: Uses caching and prefetching for faster training
48
- - ✅ **Scalable Architecture**: Easy to extend to more disease types
49
- - ✅ **Real-time Inference**: Fast prediction on new images
50
-
51
- ## 📊 Dataset
52
-
53
- ### 📈 Dataset Statistics
54
-
55
- - **Total Images**: 2,152
56
- - **Classes**: 3 (Early Blight, Late Blight, Healthy)
57
- - **Image Size**: 256×256 pixels
58
- - **Color Channels**: RGB (3 channels)
59
- - **Data Split**: 80% Train, 10% Validation, 10% Test
60
-
61
- ## 📁 Project Structure
62
-
63
- ```
64
- potato-disease-detection/
65
- ├── 📓 POTATO_Skin_Diseases_Detection_Using_Deep_Learning.ipynb
66
- ├── 📄 README.md
67
- ├── 📋 requirements.txt
68
- ├── 📁 PlantVillage/
69
- │ ├── 📁 Potato___Early_blight/
70
- │ ├── 📁 Potato___Late_blight/
71
- │ └── 📁 Potato___healthy/
72
- ├── 📁 models/
73
- │ └── 💾 trained_model.h5
74
- └── 📁 results/
75
- ├── 📊 training_plots.png
76
- └── 📈 confusion_matrix.png
77
- ```
78
-
79
- 📂 Root Directory/
80
- ├── 🐍 app.py # Main Flask application
81
- ├── 📦 requirements.txt # Dependencies
82
- ├── 🚀 run_flask_app.bat # Easy startup script
83
- ├── 📚 README_Flask.md # Complete documentation
84
- ├── 📂 templates/
85
- └── 🌐 index.html # Web interface
86
- └── 📂 static/
87
- ├── 📂 css/
88
- └── 💄 style.css # Beautiful styling
89
- └── 📂 js/
90
- └── script.js # Interactive functionality
91
-
92
- ## 🚀 Getting Started
93
-
94
- ### 📋 Prerequisites
95
-
96
- ```bash
97
- Python 3.8+
98
- TensorFlow 2.x
99
- Matplotlib
100
- NumPy
101
- ```
102
-
103
- ### Quick Start and Installation
104
-
105
- ### 🐍 Environment Setup
106
-
107
- ```bash
108
- # Create virtual environment
109
- python -m venv potato_env
110
-
111
- # Activate environment
112
- # Windows:
113
- potato_env\Scripts\activate
114
- # macOS/Linux:
115
- source potato_env/bin/activate
116
-
117
- # Install packages
118
- pip install -r requirements.txt
119
- ```
120
-
121
- # Run Application
122
-
123
- #### **Step 1: Install Dependencies**
124
-
125
- ```cmd
126
- pip install -r requirements.txt
127
- ```
128
-
129
- #### **Step 2: Run the Application**
130
-
131
- ```cmd
132
- python app.py
133
- ```
134
-
135
- #### **Step 3: Open Your Browser**
136
-
137
- - **Main App**: http://localhost:5000
138
- - **Health Check**: http://localhost:5000/health
139
-
140
- ## 💻 Usage
141
-
142
- ### 🔧 Training the Model
143
-
144
- The notebook includes the complete pipeline:
145
-
146
- 1. **Data Loading & Preprocessing**
147
-
148
- ```python
149
- # Load dataset
150
- dataset = tf.keras.preprocessing.image_dataset_from_directory(
151
- "PlantVillage",
152
- image_size=(256, 256),
153
- batch_size=32
154
- )
155
- ```
156
-
157
- 2. **Data Augmentation**
158
-
159
- ```python
160
- # Apply data augmentation
161
- data_augmentation = tf.keras.Sequential([
162
- tf.keras.layers.RandomFlip("horizontal_and_vertical"),
163
- tf.keras.layers.RandomRotation(0.2)
164
- ])
165
- ```
166
-
167
- 3. **Model Configuration**
168
- ```python
169
- IMAGE_SIZE = 256
170
- BATCH_SIZE = 32
171
- CHANNELS = 3
172
- EPOCHS = 50
173
- ```
174
-
175
- ### 🎯 Making Predictions
176
-
177
- ```python
178
- # Load your trained model
179
- model = tf.keras.models.load_model('potato_disease_model.h5')
180
-
181
- # Make prediction
182
- prediction = model.predict(new_image)
183
- predicted_class = class_names[np.argmax(prediction)]
184
- ```
185
-
186
- ## 🏗️ Model Architecture
187
-
188
- ### 🧠 Network Components
189
-
190
- 1. **Input Layer**: 256×256×3 RGB images
191
- 2. **Preprocessing**:
192
- - Image resizing and rescaling (1.0/255)
193
- - Data augmentation (RandomFlip, RandomRotation)
194
- 3. **Feature Extraction**: CNN layers for pattern recognition
195
- 4. **Classification**: Dense layers for final prediction
196
-
197
- ### ⚙️ Training Configuration
198
-
199
- - **Optimizer**: Adam (recommended)
200
- - **Loss Function**: Sparse Categorical Crossentropy
201
- - **Metrics**: Accuracy
202
- - **Epochs**: 50
203
- - **Batch Size**: 32
204
-
205
- ## 📈 Results
206
-
207
- ### 📊 Performance Metrics
208
-
209
- | Metric | Score |
210
- | ------------------- | ----- |
211
- | Training Accuracy | XX.X% |
212
- | Validation Accuracy | XX.X% |
213
- | Test Accuracy | XX.X% |
214
- | F1-Score | XX.X% |
215
-
216
- ### 🎨 Visualization
217
-
218
- The notebook includes:
219
-
220
- - ✅ Sample image visualization
221
- - Training/validation loss curves
222
- - ✅ Confusion matrix
223
- - Class-wise accuracy
224
-
225
- # 🥔 Potato Disease Detection - Flask Web Application
226
-
227
- A modern Flask web application for detecting potato diseases using deep learning. Upload images or use your camera to get instant disease predictions with confidence scores and treatment recommendations.
228
-
229
- ## ✨ Features
230
-
231
- ### 🖼️ **Dual Input Methods**
232
-
233
- - **📁 File Upload**: Drag & drop or browse to select images
234
- - **📸 Camera Capture**: Take photos directly from your device camera
235
-
236
- ### 🧠 **AI-Powered Detection**
237
-
238
- - **🎯 Accurate Predictions**: Uses trained CNN model for disease detection
239
- - **📊 Confidence Scores**: Shows prediction confidence with color-coded badges
240
- - **📈 Probability Breakdown**: Displays probabilities for all disease classes
241
-
242
- ### 💡 **Smart Recommendations**
243
-
244
- - **🏥 Treatment Advice**: Provides specific recommendations for each condition
245
- - **🚨 Urgency Levels**: Different advice based on disease severity
246
- - **📋 Downloadable Reports**: Generate and download analysis reports
247
-
248
- ### 🎨 **Modern Interface**
249
-
250
- - **📱 Responsive Design**: Works perfectly on mobile and desktop
251
- - **🌟 Beautiful UI**: Modern design with smooth animations
252
- - **🔄 Real-time Analysis**: Instant predictions with loading indicators
253
-
254
- ## 🦠 Detected Diseases
255
-
256
- 1. **🍂 Early Blight** - Common fungal disease affecting potato leaves
257
- 2. **💀 Late Blight** - Serious disease that can destroy entire crops
258
- 3. **✅ Healthy** - No disease detected
259
-
260
- ## 🎯 How to Use
261
-
262
- ### **📁 Upload Method**
263
-
264
- 1. **Select Upload** tab (default)
265
- 2. **Drag & drop** an image or **click to browse**
266
- 3. **Click "Analyze Disease"** button
267
- 4. **View results** with predictions and recommendations
268
-
269
- ### **📸 Camera Method**
270
-
271
- 1. **Click Camera** tab
272
- 2. **Click "Start Camera"** (allow permissions)
273
- 3. **Click "Capture Photo"** when ready
274
- 4. **Click "Analyze Disease"** button
275
- 5. **View results** with predictions and recommendations
276
-
277
- ### **📊 Understanding Results**
278
-
279
- - **🎯 Primary Diagnosis**: Main prediction with confidence score
280
- - **📈 Probability Breakdown**: All disease probabilities
281
- - **💡 Recommendations**: Treatment and care advice
282
- - **📋 Download Report**: Save results as text file
283
-
284
- ## 🔧 Technical Details
285
-
286
- - **🐍 Backend**: Flask 2.3+ with Python
287
- - **🧠 AI Model**: TensorFlow/Keras CNN
288
- - **🖼️ Image Processing**: PIL/Pillow for preprocessing
289
- - **🎨 Frontend**: HTML5, CSS3, Vanilla JavaScript
290
- - **📱 Camera**: WebRTC getUserMedia API
291
- - **💾 Storage**: Local file system for uploads
292
-
293
- ## 📋 Requirements
294
-
295
- - **🐍 Python**: 3.8+ (Recommended: 3.10+)
296
- - **💻 OS**: Windows, macOS, or Linux
297
- - **🧠 Memory**: 4GB+ RAM (8GB recommended)
298
- - **💾 Storage**: ~2GB for dependencies and models
299
- - **🌐 Browser**: Chrome, Firefox, Safari, Edge (latest versions)
300
-
301
- ## 🛠️ Troubleshooting
302
-
303
- ### **Model Not Loading**
304
-
305
- ```
306
- Error: Model not loaded! Please check the model file path.
307
- ```
308
-
309
- **Solution:**
310
-
311
- - Ensure `models/1.h5` exists
312
- - Check TensorFlow installation: `pip install tensorflow>=2.13.0`
313
-
314
- ### ❌ **Camera Not Working**
315
-
316
- ```
317
- Could not access camera. Please check permissions.
318
- ```
319
-
320
- **Solution:**
321
-
322
- - Allow camera permissions in your browser
323
- - Use HTTPS for camera access (or localhost)
324
- - Check if another app is using the camera
325
-
326
- ### **Port Already in Use**
327
-
328
- ```
329
- Address already in use
330
- ```
331
-
332
- **Solution:**
333
-
334
- - Close other Flask applications
335
- - Change port in `app.py`: `app.run(port=5001)`
336
- - Kill process: `taskkill /f /im python.exe` (Windows)
337
-
338
- ### **File Upload Issues**
339
-
340
- ```
341
- Invalid file type or File too large
342
- ```
343
-
344
- **Solution:**
345
-
346
- - Use supported formats: PNG, JPG, JPEG
347
- - Keep file size under 16MB
348
- - Check image isn't corrupted
349
-
350
- ## 🎨 Customization
351
-
352
- ### **🎯 Add New Disease Classes**
353
-
354
- 1. Update `CLASS_NAMES` in `app.py`
355
- 2. Add descriptions in `CLASS_DESCRIPTIONS`
356
- 3. Update recommendations in `get_recommendations()`
357
- 4. Retrain model with new classes
358
-
359
- ## 📱 Mobile Responsiveness
360
-
361
- The application is now **fully responsive** and optimized for mobile devices:
362
-
363
- ### 📲 Mobile Features:
364
-
365
- - ✅ **Touch-friendly interface** with larger touch targets (44px minimum)
366
- - **Responsive design** that adapts to screen sizes from 320px to desktop
367
- - ✅ **Mobile camera support** with environment (back) camera preference
368
- - **Optimized image display** for mobile viewports
369
- - **Landscape/Portrait orientation** support
370
- - **iOS Safari compatibility** with viewport fixes
371
- - **Prevent accidental zoom** on form inputs
372
- - ✅ **Touch-optimized drag & drop** for file uploads
373
-
374
- ### **🎨 Modify UI**
375
-
376
- - **Colors**: Edit CSS variables in `style.css`
377
- - **Layout**: Modify templates in `templates/`
378
- - **Functionality**: Update JavaScript in `static/js/`
379
-
380
- ### **⚙️ Configuration**
381
-
382
- - **Upload size**: Change `MAX_CONTENT_LENGTH` in `app.py`
383
- - **Image size**: Modify `IMAGE_SIZE` parameter
384
- - **Port**: Update `app.run(port=5000)` line
385
-
386
- ## 🔒 Security Notes
387
-
388
- - **🚫 Production Use**: This is for development/research only
389
- - **🔐 Secret Key**: Change `app.secret_key` for production
390
- - **📁 File Validation**: Only accepts image files
391
- - **💾 File Cleanup**: Consider automatic cleanup of old uploads
392
-
393
- ## 📈 Performance Tips
394
-
395
- - **📸 Image Quality**: Use clear, well-lit potato leaf images
396
- - **🎯 Focus**: Ensure leaves fill most of the frame
397
- - **📏 Size**: Optimal size is 256x256 pixels or larger
398
- - **🌟 Lighting**: Good natural lighting gives best results
399
-
400
- ## 🌐 Browser Compatibility
401
-
402
- - **Chrome**: 90+
403
- - **Firefox**: 88+
404
- - **Safari**: 14+
405
- - **Edge**: 90+
406
- - ⚠️ **Mobile**: Camera features may vary
407
-
408
- ## 📄 API Endpoints
409
-
410
- - `GET /` - Main web interface
411
- - `POST /predict` - Upload image prediction
412
- - `POST /predict_camera` - Camera image prediction
413
- - `GET /health` - Application health check
414
-
415
- ## 🤝 Support
416
-
417
- For issues or questions:
418
-
419
- 1. Check the troubleshooting section above
420
- 2. Verify your Python and dependencies versions
421
- 3. Ensure model files are in the correct location
422
- 4. Test with the provided sample images
423
-
424
- ---
425
-
426
- ## 🚀 Next Steps
427
-
428
- ### 🔮 Future Enhancements
429
-
430
- - [ ] **Model Optimization**: Implement transfer learning with pre-trained models
431
- - [ ] **Web Application**: Create a Flask/Streamlit web interface
432
- - [ ] **Mobile App**: Develop a mobile application for field use
433
- - [ ] **More Diseases**: Expand to detect additional potato diseases
434
- - [ ] **Real-time Detection**: Implement live camera feed processing
435
- - [ ] **API Development**: Create REST API for integration
436
-
437
- ### 🎯 Improvement Ideas
438
-
439
- - [ ] **Hyperparameter Tuning**: Optimize model parameters
440
- - [ ] **Cross-validation**: Implement k-fold cross-validation
441
- - [ ] **Ensemble Methods**: Combine multiple models
442
- - [ ] **Data Balancing**: Handle class imbalance if present
443
-
444
- ### 🐛 Bug Reports
445
-
446
- If you find a bug, please create an issue with:
447
-
448
- - Description of the problem
449
- - Steps to reproduce
450
- - Expected vs actual behavior
451
- - System information
452
-
453
- ### 💡 Feature Requests
454
-
455
- For new features, please provide:
456
-
457
- - Clear description of the feature
458
- - Use case and benefits
459
- - Implementation suggestions```
460
-
461
- # ==================DEBUGGING AND TROUBLESHOOTING GUIDE:===========================
462
-
463
- # 🥔 Potato Disease Detection - Upload Functionality Guide
464
-
465
- ## 🚀 Quick Start
466
-
467
- 1. **Run the Application**:
468
-
469
- ```bash
470
- python app.py
471
- ```
472
-
473
- Or double-click `run_and_test.bat`
474
-
475
- 2. **Access the App**:
476
- - Main app: http://localhost:5000
477
- - Debug upload page: http://localhost:5000/debug
478
- - Health check: http://localhost:5000/health
479
-
480
- ## 📋 Testing Upload Functionality
481
-
482
- ### Step 1: Check System Health
483
-
484
- 1. Go to http://localhost:5000/debug
485
- 2. Click "🔍 Check System Health"
486
- 3. Verify all items show ✅:
487
- - Status: healthy
488
- - Model Loaded: Yes
489
- - Upload Dir Exists: Yes
490
- - Upload Dir Writable: Yes
491
-
492
- ### Step 2: Test Upload Directory
493
-
494
- 1. Click "📂 Test Upload Directory"
495
- 2. Should show "Upload directory is working correctly"
496
-
497
- ### Step 3: Test Image Upload
498
-
499
- 1. Click "📁 Click here to select an image" or drag an image
500
- 2. Select a potato leaf image (JPG, PNG, JPEG)
501
- 3. Preview should appear
502
- 4. Click "🔬 Analyze Disease"
503
- 5. Results should show:
504
- - Disease name and confidence
505
- - Recommendations
506
- - The analyzed image displayed
507
-
508
- ## 🔧 Troubleshooting Upload Issues
509
-
510
- ### Issue: "No file uploaded" Error
511
-
512
- **Solutions:**
513
-
514
- 1. Ensure you're clicking the upload area or browse link
515
- 2. Check browser console for JavaScript errors (F12)
516
- 3. Try the debug page: http://localhost:5000/debug
517
- 4. **Mobile**: Tap firmly on upload area, wait for file picker
518
-
519
- ### Issue: File Not Saving
520
-
521
- **Solutions:**
522
-
523
- 1. Check upload directory permissions:
524
- ```bash
525
- mkdir static/uploads
526
- ```
527
- 2. Run as administrator if on Windows
528
- 3. Check disk space
529
- 4. **Mobile**: Ensure stable network connection
530
-
531
- ### Issue: Camera Not Working (Mobile)
532
-
533
- **Solutions:**
534
-
535
- 1. **Grant camera permissions** when prompted
536
- 2. **Use HTTPS** for camera access on mobile (required by browsers)
537
- 3. **Check camera availability** - some devices block camera access
538
- 4. **Try different browsers** (Chrome/Safari work best)
539
- 5. **Close other camera apps** that might be using the camera
540
-
541
- ### Issue: Touch/Tap Not Working (Mobile)
542
-
543
- **Solutions:**
544
-
545
- 1. **Clear browser cache** and reload
546
- 2. **Disable browser zoom** if enabled
547
- 3. **Try two-finger tap** if single tap doesn't work
548
- 4. **Check touch targets** - buttons should be at least 44px
549
- 5. **Restart browser app** on mobile device
550
-
551
- ### Issue: Image Too Small/Large on Mobile
552
-
553
- **Solutions:**
554
-
555
- 1. **Portrait orientation** usually works better
556
- 2. **Pinch to zoom** on images if needed
557
- 3. **Landscape mode** available for wider screens
558
- 4. **Image auto-resizes** based on screen size
559
-
560
- ### Issue: Slow Performance on Mobile
561
-
562
- **Solutions:**
563
-
564
- 1. **Close other browser tabs** to free memory
565
- 2. **Use smaller image files** (under 5MB recommended)
566
- 3. **Ensure good network connection** for uploads
567
- 4. **Clear browser cache** regularly
568
- 5. **Restart browser** if app becomes unresponsive
569
-
570
- ### Issue: Model Not Loading
571
-
572
- **Solutions:**
573
-
574
- 1. Verify model file exists: `models/1.h5`
575
- 2. Install required packages:
576
- ```bash
577
- pip install tensorflow pillow flask
578
- ```
579
-
580
- ### Issue: JavaScript Errors
581
-
582
- **Solutions:**
583
-
584
- 1. Clear browser cache (Ctrl+F5)
585
- 2. Check browser console (F12)
586
- 3. Try a different browser
587
- 4. Disable browser extensions
588
-
589
- ### Issue: Image Not Displaying in Results
590
-
591
- **Solutions:**
592
-
593
- 1. Check browser network tab (F12) for failed requests
594
- 2. Verify uploaded file in `static/uploads/` folder
595
- 3. Check Flask console for file save errors
596
-
597
- ## 🧪 Debug Features
598
-
599
- ### Console Logging
600
-
601
- The JavaScript includes extensive console logging. Open browser developer tools (F12) to see:
602
-
603
- - File selection events
604
- - Upload progress
605
- - Server responses
606
- - Error details
607
-
608
- ### Debug Endpoints
609
-
610
- - `/health` - System status
611
- - `/debug/upload-test` - Upload directory test
612
- - `/debug` - Interactive upload test page
613
-
614
- ### Manual Testing
615
-
616
- 1. **File Input Test**:
617
-
618
- ```javascript
619
- document.getElementById("fileInput").click();
620
- ```
621
-
622
- 2. **Check Selected File**:
623
-
624
- ```javascript
625
- console.log(selectedFile);
626
- ```
627
-
628
- 3. **Test FormData**:
629
- ```javascript
630
- const formData = new FormData();
631
- formData.append("file", selectedFile);
632
- console.log([...formData.entries()]);
633
- ```
634
-
635
- ## 💡 Tips for Success
636
-
637
- 1. **Use supported image formats**: JPG, PNG, JPEG, GIF
638
- 2. **Keep file size under 16MB**
639
- 3. **Use clear potato leaf images**
640
- 4. **Check browser compatibility** (modern browsers work best)
641
- 5. **Enable JavaScript**
642
- 6. **Allow camera permissions** (for camera capture feature)
643
-
644
- ## 🆘 Getting Help
645
-
646
- If upload functionality still doesn't work:
647
-
648
- 1. **Check Flask console output** for error messages
649
- 2. **Check browser console** (F12 → Console tab)
650
- 3. **Try the debug page** at `/debug`
651
- 4. **Test with different image files**
652
- 5. **Restart the Flask app**
653
- 6. **Check file permissions** on the upload directory
654
-
655
- ## 🎯 Expected Results
656
-
657
- After successful upload and analysis:
658
-
659
- - ✅ Disease classification (Early Blight, Late Blight, or Healthy)
660
- - Confidence percentage
661
- - ✅ Treatment recommendations
662
- - Analyzed image displayed in results
663
- - Timestamp of analysis
664
-
665
- # PDF Report Download Upgrade Guide
666
-
667
- ## 🎉 New Features Added
668
-
669
- ### **PDF Format**
670
-
671
- - Professional PDF reports instead of simple text files
672
- - Includes header, footer, tables, and proper formatting
673
- - Company branding and professional layout
674
-
675
- ### 📁 **Folder Selection**
676
-
677
- - Choose where to save your PDF reports
678
- - Modern file picker dialog (supported browsers)
679
- - Automatic fallback to default downloads folder
680
-
681
- ### 🎨 **Enhanced Report Content**
682
-
683
- - **Report Header**: Timestamp, analysis method, model version
684
- - **Analyzed Image**: Embedded image (if available)
685
- - **Diagnosis Section**: Disease name, confidence, risk assessment
686
- - **Probability Breakdown**: Table showing all class probabilities
687
- - **Treatment Recommendations**: Numbered list of actionable advice
688
- - **Professional Footer**: Branding and copyright information
689
-
690
- ## 🚀 Installation Requirements
691
-
692
- Add to your `requirements.txt`:
693
-
694
- ```
695
- reportlab>=4.0.0
696
- ```
697
-
698
- Install the new dependency:
699
-
700
- ```bash
701
- pip install reportlab>=4.0.0
702
- ```
703
-
704
- # PDF Generation Troubleshooting Guide
705
-
706
- ## 🔧 If PDF Generation is Failing
707
-
708
- ### Quick Fix Steps
709
-
710
- 1. **Install ReportLab Library**
711
-
712
- ```bash
713
- pip install reportlab>=4.0.0
714
- ```
715
-
716
- 2. **Run Installation Script**
717
-
718
- - **Windows**: Double-click `install_pdf_deps.bat`
719
- - **Linux/Mac**: Run `bash install_pdf_deps.sh`
720
-
721
- 3. **Restart the Application**
722
- ```bash
723
- python app.py
724
- ```
725
-
726
- ### Common Issues and Solutions
727
-
728
- #### ❌ **"ReportLab not available" Error**
729
-
730
- **Problem**: ReportLab library is not installed.
731
-
732
- **Solution**:
733
-
734
- ```bash
735
- pip install reportlab
736
- # or
737
- pip install reportlab>=4.0.0
738
- ```
739
-
740
- **Alternative**: Use virtual environment
741
-
742
- ```bash
743
- python -m venv pdf_env
744
- source pdf_env/bin/activate # Linux/Mac
745
- # or
746
- pdf_env\Scripts\activate # Windows
747
- pip install reportlab
748
- ```
749
-
750
- #### ❌ **"Permission denied" or "Access denied" Errors**
751
-
752
- **Problem**: Insufficient permissions to install packages.
753
-
754
- **Solutions**:
755
-
756
- 1. **Use --user flag**:
757
-
758
- ```bash
759
- pip install --user reportlab
760
- ```
761
-
762
- 2. **Run as administrator** (Windows):
763
-
764
- - Right-click Command Prompt "Run as administrator"
765
- - Then run: `pip install reportlab`
766
-
767
- 3. **Use sudo** (Linux/Mac):
768
- ```bash
769
- sudo pip install reportlab
770
- ```
771
-
772
- #### ❌ **"Module not found" Error Despite Installation**
773
-
774
- **Problem**: ReportLab installed in different Python environment.
775
-
776
- **Solutions**:
777
-
778
- 1. **Check Python version**:
779
-
780
- ```bash
781
- python --version
782
- which python # Linux/Mac
783
- where python # Windows
784
- ```
785
-
786
- 2. **Install for specific Python version**:
787
-
788
- ```bash
789
- python3 -m pip install reportlab
790
- # or
791
- python3.9 -m pip install reportlab
792
- ```
793
-
794
- 3. **Verify installation**:
795
- ```bash
796
- python -c "import reportlab; print('ReportLab available')"
797
- ```
798
-
799
- #### ❌ **PDF Generation Works but Images Missing**
800
-
801
- **Problem**: Image files not accessible or corrupted.
802
-
803
- **Solutions**:
804
-
805
- 1. **Check upload folder permissions**:
806
-
807
- ```bash
808
- ls -la static/uploads/ # Linux/Mac
809
- dir static\uploads\ # Windows
810
- ```
811
-
812
- 2. **Verify image exists**:
813
-
814
- - Check browser developer tools for 404 errors
815
- - Ensure images are properly saved during upload
816
-
817
- 3. **Check image format**:
818
- - Ensure images are JPG, PNG, or supported formats
819
- - ReportLab may have issues with some image formats
820
-
821
- #### ❌ **Client-side PDF Generation Fails**
822
-
823
- **Problem**: jsPDF library not loading.
824
-
825
- **Solutions**:
826
-
827
- 1. **Check internet connection** (jsPDF loads from CDN)
828
-
829
- 2. **Check browser console** for JavaScript errors
830
-
831
- #### **Folder Selection Not Working**
832
-
833
- **Problem**: File System Access API not supported.
834
-
835
- **Solutions**:
836
-
837
- 1. **Update browser**:
838
-
839
- - Chrome 86+ or Edge 86+ required for folder selection
840
- - Firefox and Safari will use default download folder
841
-
842
- 2. **Enable experimental features** (Chrome):
843
-
844
- - Go to `chrome://flags`
845
- - Enable "Experimental Web Platform features"
846
-
847
- 3. **Accept automatic download** to default folder
848
-
849
- The system should work with any clear image of a potato plant leaf!
850
-
851
- ## 📄 License
852
-
853
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
854
-
855
- ## 🙏 Acknowledgments
856
-
857
- - **PlantVillage Dataset**: For providing the potato disease dataset
858
- - **TensorFlow Team**: For the amazing deep learning framework
859
- - **Open Source Community**: For inspiration and resources
860
-
861
- ## 📞 Contact
862
-
863
- - **Author**: Lucky Sharma
864
- - **Email**: [email protected]
865
- - **LinkedIn**: https://www.linkedin.com/in/lucky-sharma918894599977
866
- - **GitHub**: https://github.com/itsluckysharma01
867
-
868
- ---
869
-
870
- <div align="center">
871
- <p>⭐ Star this repository if you found it helpful!</p>
872
- <p>🍀 Happy coding and may your potatoes be healthy!</p>
873
- </div>
874
- "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Potato_Diseases_Detection_with_Deep_Learning
3
+ emoji: 🐨
4
+ colorFrom: purple
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ license: apache-2.0
9
+ ---
10
+
11
+
12
+
13
+
14
+
15
+ # 🥔 Potato Skin Disease Detection Using Deep Learning
16
+
17
+ [![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/)
18
+ [![TensorFlow](https://img.shields.io/badge/TensorFlow-2.x-orange.svg)](https://tensorflow.org/)
19
+ [![Keras](https://img.shields.io/badge/Keras-2.x-red.svg)](https://keras.io/)
20
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
21
+
22
+ > 🔬 An AI-powered computer vision system for detecting and classifying potato skin diseases using deep learning techniques.
23
+
24
+ ## 📋 Table of Contents
25
+
26
+ - [🎯 Project Overview](#-project-overview)
27
+ - [🌟 Features](#-features)
28
+ - [📊 Dataset](#-dataset)
29
+ - [🚀 Getting Started](#-getting-started)
30
+ - [💻 Usage](#-usage)
31
+ - [🏗️ Model Architecture](#-model-architecture)
32
+ - [📈 Results](#-results)
33
+ - [🚀 Next Steps](#-Next-Steps)
34
+ - [📄 License](#-license)
35
+
36
+ ## 🎯 Project Overview
37
+
38
+ This project implements a **Convolutional Neural Network (CNN)** using TensorFlow/Keras to automatically detect and classify potato skin diseases from digital images. The system can identify three main categories:
39
+
40
+ - 🍃 **Healthy Potatoes**
41
+ - 🦠 **Early Blight Disease**
42
+ - 🍄 **Late Blight Disease**
43
+
44
+ ### 🎥 Demo
45
+
46
+ <details>
47
+ <summary>Click to see sample predictions</summary>
48
+
49
+ ```
50
+ Input: potato_image.jpg
51
+ Output: "Early Blight Disease" (Confidence: 94.2%)
52
+ ```
53
+
54
+ </details>
55
+
56
+ ## 🌟 Features
57
+
58
+ - **Multi-class Classification**: Detects 3 types of potato conditions
59
+ - **Data Augmentation**: Improves model robustness with image transformations
60
+ - ✅ **Interactive Visualization**: Displays sample images with predictions
61
+ - **Optimized Performance**: Uses caching and prefetching for faster training
62
+ - ✅ **Scalable Architecture**: Easy to extend to more disease types
63
+ - ✅ **Real-time Inference**: Fast prediction on new images
64
+
65
+ ## 📊 Dataset
66
+
67
+ ### 📈 Dataset Statistics
68
+
69
+ - **Total Images**: 2,152
70
+ - **Classes**: 3 (Early Blight, Late Blight, Healthy)
71
+ - **Image Size**: 256×256 pixels
72
+ - **Color Channels**: RGB (3 channels)
73
+ - **Data Split**: 80% Train, 10% Validation, 10% Test
74
+
75
+ ## 📁 Project Structure
76
+
77
+ ```
78
+ potato-disease-detection/
79
+ ├── 📓 POTATO_Skin_Diseases_Detection_Using_Deep_Learning.ipynb
80
+ ├── 📄 README.md
81
+ ├── 📋 requirements.txt
82
+ ├── 📁 PlantVillage/
83
+ ├── 📁 Potato___Early_blight/
84
+ ├── 📁 Potato___Late_blight/
85
+ └── 📁 Potato___healthy/
86
+ ├── 📁 models/
87
+ │ └── 💾 trained_model.h5
88
+ └── 📁 results/
89
+ ├── 📊 training_plots.png
90
+ └── 📈 confusion_matrix.png
91
+ ```
92
+
93
+ 📂 Root Directory/
94
+ ├── 🐍 app.py # Main Flask application
95
+ ├── 📦 requirements.txt # Dependencies
96
+ ├── 🚀 run_flask_app.bat # Easy startup script
97
+ ├── 📚 README_Flask.md # Complete documentation
98
+ ├── 📂 templates/
99
+ │ └── 🌐 index.html # Web interface
100
+ └── 📂 static/
101
+ ├── 📂 css/
102
+ │ └── 💄 style.css # Beautiful styling
103
+ └── 📂 js/
104
+ └── ⚡ script.js # Interactive functionality
105
+
106
+ ## 🚀 Getting Started
107
+
108
+ ### 📋 Prerequisites
109
+
110
+ ```bash
111
+ Python 3.8+
112
+ TensorFlow 2.x
113
+ Matplotlib
114
+ NumPy
115
+ ```
116
+
117
+ ### Quick Start and Installation
118
+
119
+ ### 🐍 Environment Setup
120
+
121
+ ```bash
122
+ # Create virtual environment
123
+ python -m venv potato_env
124
+
125
+ # Activate environment
126
+ # Windows:
127
+ potato_env\Scripts\activate
128
+ # macOS/Linux:
129
+ source potato_env/bin/activate
130
+
131
+ # Install packages
132
+ pip install -r requirements.txt
133
+ ```
134
+
135
+ # Run Application
136
+
137
+ #### **Step 1: Install Dependencies**
138
+
139
+ ```cmd
140
+ pip install -r requirements.txt
141
+ ```
142
+
143
+ #### **Step 2: Run the Application**
144
+
145
+ ```cmd
146
+ python app.py
147
+ ```
148
+
149
+ #### **Step 3: Open Your Browser**
150
+
151
+ - **Main App**: http://localhost:5000
152
+ - **Health Check**: http://localhost:5000/health
153
+
154
+ ## 💻 Usage
155
+
156
+ ### 🔧 Training the Model
157
+
158
+ The notebook includes the complete pipeline:
159
+
160
+ 1. **Data Loading & Preprocessing**
161
+
162
+ ```python
163
+ # Load dataset
164
+ dataset = tf.keras.preprocessing.image_dataset_from_directory(
165
+ "PlantVillage",
166
+ image_size=(256, 256),
167
+ batch_size=32
168
+ )
169
+ ```
170
+
171
+ 2. **Data Augmentation**
172
+
173
+ ```python
174
+ # Apply data augmentation
175
+ data_augmentation = tf.keras.Sequential([
176
+ tf.keras.layers.RandomFlip("horizontal_and_vertical"),
177
+ tf.keras.layers.RandomRotation(0.2)
178
+ ])
179
+ ```
180
+
181
+ 3. **Model Configuration**
182
+ ```python
183
+ IMAGE_SIZE = 256
184
+ BATCH_SIZE = 32
185
+ CHANNELS = 3
186
+ EPOCHS = 50
187
+ ```
188
+
189
+ ### 🎯 Making Predictions
190
+
191
+ ```python
192
+ # Load your trained model
193
+ model = tf.keras.models.load_model('potato_disease_model.h5')
194
+
195
+ # Make prediction
196
+ prediction = model.predict(new_image)
197
+ predicted_class = class_names[np.argmax(prediction)]
198
+ ```
199
+
200
+ ## 🏗️ Model Architecture
201
+
202
+ ### 🧠 Network Components
203
+
204
+ 1. **Input Layer**: 256×256×3 RGB images
205
+ 2. **Preprocessing**:
206
+ - Image resizing and rescaling (1.0/255)
207
+ - Data augmentation (RandomFlip, RandomRotation)
208
+ 3. **Feature Extraction**: CNN layers for pattern recognition
209
+ 4. **Classification**: Dense layers for final prediction
210
+
211
+ ### ⚙️ Training Configuration
212
+
213
+ - **Optimizer**: Adam (recommended)
214
+ - **Loss Function**: Sparse Categorical Crossentropy
215
+ - **Metrics**: Accuracy
216
+ - **Epochs**: 50
217
+ - **Batch Size**: 32
218
+
219
+ ## 📈 Results
220
+
221
+ ### 📊 Performance Metrics
222
+
223
+ | Metric | Score |
224
+ | ------------------- | ----- |
225
+ | Training Accuracy | XX.X% |
226
+ | Validation Accuracy | XX.X% |
227
+ | Test Accuracy | XX.X% |
228
+ | F1-Score | XX.X% |
229
+
230
+ ### 🎨 Visualization
231
+
232
+ The notebook includes:
233
+
234
+ - Sample image visualization
235
+ - ✅ Training/validation loss curves
236
+ - Confusion matrix
237
+ - ✅ Class-wise accuracy
238
+
239
+ # 🥔 Potato Disease Detection - Flask Web Application
240
+
241
+ A modern Flask web application for detecting potato diseases using deep learning. Upload images or use your camera to get instant disease predictions with confidence scores and treatment recommendations.
242
+
243
+ ## ✨ Features
244
+
245
+ ### 🖼️ **Dual Input Methods**
246
+
247
+ - **📁 File Upload**: Drag & drop or browse to select images
248
+ - **📸 Camera Capture**: Take photos directly from your device camera
249
+
250
+ ### 🧠 **AI-Powered Detection**
251
+
252
+ - **🎯 Accurate Predictions**: Uses trained CNN model for disease detection
253
+ - **📊 Confidence Scores**: Shows prediction confidence with color-coded badges
254
+ - **📈 Probability Breakdown**: Displays probabilities for all disease classes
255
+
256
+ ### 💡 **Smart Recommendations**
257
+
258
+ - **🏥 Treatment Advice**: Provides specific recommendations for each condition
259
+ - **🚨 Urgency Levels**: Different advice based on disease severity
260
+ - **📋 Downloadable Reports**: Generate and download analysis reports
261
+
262
+ ### 🎨 **Modern Interface**
263
+
264
+ - **📱 Responsive Design**: Works perfectly on mobile and desktop
265
+ - **🌟 Beautiful UI**: Modern design with smooth animations
266
+ - **🔄 Real-time Analysis**: Instant predictions with loading indicators
267
+
268
+ ## 🦠 Detected Diseases
269
+
270
+ 1. **🍂 Early Blight** - Common fungal disease affecting potato leaves
271
+ 2. **💀 Late Blight** - Serious disease that can destroy entire crops
272
+ 3. **✅ Healthy** - No disease detected
273
+
274
+ ## 🎯 How to Use
275
+
276
+ ### **📁 Upload Method**
277
+
278
+ 1. **Select Upload** tab (default)
279
+ 2. **Drag & drop** an image or **click to browse**
280
+ 3. **Click "Analyze Disease"** button
281
+ 4. **View results** with predictions and recommendations
282
+
283
+ ### **📸 Camera Method**
284
+
285
+ 1. **Click Camera** tab
286
+ 2. **Click "Start Camera"** (allow permissions)
287
+ 3. **Click "Capture Photo"** when ready
288
+ 4. **Click "Analyze Disease"** button
289
+ 5. **View results** with predictions and recommendations
290
+
291
+ ### **📊 Understanding Results**
292
+
293
+ - **🎯 Primary Diagnosis**: Main prediction with confidence score
294
+ - **📈 Probability Breakdown**: All disease probabilities
295
+ - **💡 Recommendations**: Treatment and care advice
296
+ - **📋 Download Report**: Save results as text file
297
+
298
+ ## 🔧 Technical Details
299
+
300
+ - **🐍 Backend**: Flask 2.3+ with Python
301
+ - **🧠 AI Model**: TensorFlow/Keras CNN
302
+ - **🖼️ Image Processing**: PIL/Pillow for preprocessing
303
+ - **🎨 Frontend**: HTML5, CSS3, Vanilla JavaScript
304
+ - **📱 Camera**: WebRTC getUserMedia API
305
+ - **💾 Storage**: Local file system for uploads
306
+
307
+ ## 📋 Requirements
308
+
309
+ - **🐍 Python**: 3.8+ (Recommended: 3.10+)
310
+ - **💻 OS**: Windows, macOS, or Linux
311
+ - **🧠 Memory**: 4GB+ RAM (8GB recommended)
312
+ - **💾 Storage**: ~2GB for dependencies and models
313
+ - **🌐 Browser**: Chrome, Firefox, Safari, Edge (latest versions)
314
+
315
+ ## 🛠️ Troubleshooting
316
+
317
+ ### **Model Not Loading**
318
+
319
+ ```
320
+ Error: Model not loaded! Please check the model file path.
321
+ ```
322
+
323
+ **Solution:**
324
+
325
+ - Ensure `models/1.h5` exists
326
+ - Check TensorFlow installation: `pip install tensorflow>=2.13.0`
327
+
328
+ ### ❌ **Camera Not Working**
329
+
330
+ ```
331
+ Could not access camera. Please check permissions.
332
+ ```
333
+
334
+ **Solution:**
335
+
336
+ - Allow camera permissions in your browser
337
+ - Use HTTPS for camera access (or localhost)
338
+ - Check if another app is using the camera
339
+
340
+ ### ❌ **Port Already in Use**
341
+
342
+ ```
343
+ Address already in use
344
+ ```
345
+
346
+ **Solution:**
347
+
348
+ - Close other Flask applications
349
+ - Change port in `app.py`: `app.run(port=5001)`
350
+ - Kill process: `taskkill /f /im python.exe` (Windows)
351
+
352
+ ### **File Upload Issues**
353
+
354
+ ```
355
+ Invalid file type or File too large
356
+ ```
357
+
358
+ **Solution:**
359
+
360
+ - Use supported formats: PNG, JPG, JPEG
361
+ - Keep file size under 16MB
362
+ - Check image isn't corrupted
363
+
364
+ ## 🎨 Customization
365
+
366
+ ### **🎯 Add New Disease Classes**
367
+
368
+ 1. Update `CLASS_NAMES` in `app.py`
369
+ 2. Add descriptions in `CLASS_DESCRIPTIONS`
370
+ 3. Update recommendations in `get_recommendations()`
371
+ 4. Retrain model with new classes
372
+
373
+ ## 📱 Mobile Responsiveness
374
+
375
+ The application is now **fully responsive** and optimized for mobile devices:
376
+
377
+ ### 📲 Mobile Features:
378
+
379
+ - ✅ **Touch-friendly interface** with larger touch targets (44px minimum)
380
+ - **Responsive design** that adapts to screen sizes from 320px to desktop
381
+ - ✅ **Mobile camera support** with environment (back) camera preference
382
+ - **Optimized image display** for mobile viewports
383
+ - **Landscape/Portrait orientation** support
384
+ - **iOS Safari compatibility** with viewport fixes
385
+ - ✅ **Prevent accidental zoom** on form inputs
386
+ - **Touch-optimized drag & drop** for file uploads
387
+
388
+ ### **🎨 Modify UI**
389
+
390
+ - **Colors**: Edit CSS variables in `style.css`
391
+ - **Layout**: Modify templates in `templates/`
392
+ - **Functionality**: Update JavaScript in `static/js/`
393
+
394
+ ### **⚙️ Configuration**
395
+
396
+ - **Upload size**: Change `MAX_CONTENT_LENGTH` in `app.py`
397
+ - **Image size**: Modify `IMAGE_SIZE` parameter
398
+ - **Port**: Update `app.run(port=5000)` line
399
+
400
+ ## 🔒 Security Notes
401
+
402
+ - **🚫 Production Use**: This is for development/research only
403
+ - **🔐 Secret Key**: Change `app.secret_key` for production
404
+ - **📁 File Validation**: Only accepts image files
405
+ - **💾 File Cleanup**: Consider automatic cleanup of old uploads
406
+
407
+ ## 📈 Performance Tips
408
+
409
+ - **📸 Image Quality**: Use clear, well-lit potato leaf images
410
+ - **🎯 Focus**: Ensure leaves fill most of the frame
411
+ - **📏 Size**: Optimal size is 256x256 pixels or larger
412
+ - **🌟 Lighting**: Good natural lighting gives best results
413
+
414
+ ## 🌐 Browser Compatibility
415
+
416
+ - ✅ **Chrome**: 90+
417
+ - **Firefox**: 88+
418
+ - ✅ **Safari**: 14+
419
+ - **Edge**: 90+
420
+ - ⚠️ **Mobile**: Camera features may vary
421
+
422
+ ## 📄 API Endpoints
423
+
424
+ - `GET /` - Main web interface
425
+ - `POST /predict` - Upload image prediction
426
+ - `POST /predict_camera` - Camera image prediction
427
+ - `GET /health` - Application health check
428
+
429
+ ## 🤝 Support
430
+
431
+ For issues or questions:
432
+
433
+ 1. Check the troubleshooting section above
434
+ 2. Verify your Python and dependencies versions
435
+ 3. Ensure model files are in the correct location
436
+ 4. Test with the provided sample images
437
+
438
+ ---
439
+
440
+ ## 🚀 Next Steps
441
+
442
+ ### 🔮 Future Enhancements
443
+
444
+ - [ ] **Model Optimization**: Implement transfer learning with pre-trained models
445
+ - [ ] **Web Application**: Create a Flask/Streamlit web interface
446
+ - [ ] **Mobile App**: Develop a mobile application for field use
447
+ - [ ] **More Diseases**: Expand to detect additional potato diseases
448
+ - [ ] **Real-time Detection**: Implement live camera feed processing
449
+ - [ ] **API Development**: Create REST API for integration
450
+
451
+ ### 🎯 Improvement Ideas
452
+
453
+ - [ ] **Hyperparameter Tuning**: Optimize model parameters
454
+ - [ ] **Cross-validation**: Implement k-fold cross-validation
455
+ - [ ] **Ensemble Methods**: Combine multiple models
456
+ - [ ] **Data Balancing**: Handle class imbalance if present
457
+
458
+ ### 🐛 Bug Reports
459
+
460
+ If you find a bug, please create an issue with:
461
+
462
+ - Description of the problem
463
+ - Steps to reproduce
464
+ - Expected vs actual behavior
465
+ - System information
466
+
467
+ ### 💡 Feature Requests
468
+
469
+ For new features, please provide:
470
+
471
+ - Clear description of the feature
472
+ - Use case and benefits
473
+ - Implementation suggestions```
474
+
475
+ # ==================DEBUGGING AND TROUBLESHOOTING GUIDE:===========================
476
+
477
+ # 🥔 Potato Disease Detection - Upload Functionality Guide
478
+
479
+ ## 🚀 Quick Start
480
+
481
+ 1. **Run the Application**:
482
+
483
+ ```bash
484
+ python app.py
485
+ ```
486
+
487
+ Or double-click `run_and_test.bat`
488
+
489
+ 2. **Access the App**:
490
+ - Main app: http://localhost:5000
491
+ - Debug upload page: http://localhost:5000/debug
492
+ - Health check: http://localhost:5000/health
493
+
494
+ ## 📋 Testing Upload Functionality
495
+
496
+ ### Step 1: Check System Health
497
+
498
+ 1. Go to http://localhost:5000/debug
499
+ 2. Click "🔍 Check System Health"
500
+ 3. Verify all items show ✅:
501
+ - Status: healthy
502
+ - Model Loaded: Yes
503
+ - Upload Dir Exists: Yes
504
+ - Upload Dir Writable: Yes
505
+
506
+ ### Step 2: Test Upload Directory
507
+
508
+ 1. Click "📂 Test Upload Directory"
509
+ 2. Should show "Upload directory is working correctly"
510
+
511
+ ### Step 3: Test Image Upload
512
+
513
+ 1. Click "📁 Click here to select an image" or drag an image
514
+ 2. Select a potato leaf image (JPG, PNG, JPEG)
515
+ 3. Preview should appear
516
+ 4. Click "🔬 Analyze Disease"
517
+ 5. Results should show:
518
+ - Disease name and confidence
519
+ - Recommendations
520
+ - The analyzed image displayed
521
+
522
+ ## 🔧 Troubleshooting Upload Issues
523
+
524
+ ### Issue: "No file uploaded" Error
525
+
526
+ **Solutions:**
527
+
528
+ 1. Ensure you're clicking the upload area or browse link
529
+ 2. Check browser console for JavaScript errors (F12)
530
+ 3. Try the debug page: http://localhost:5000/debug
531
+ 4. **Mobile**: Tap firmly on upload area, wait for file picker
532
+
533
+ ### Issue: File Not Saving
534
+
535
+ **Solutions:**
536
+
537
+ 1. Check upload directory permissions:
538
+ ```bash
539
+ mkdir static/uploads
540
+ ```
541
+ 2. Run as administrator if on Windows
542
+ 3. Check disk space
543
+ 4. **Mobile**: Ensure stable network connection
544
+
545
+ ### Issue: Camera Not Working (Mobile)
546
+
547
+ **Solutions:**
548
+
549
+ 1. **Grant camera permissions** when prompted
550
+ 2. **Use HTTPS** for camera access on mobile (required by browsers)
551
+ 3. **Check camera availability** - some devices block camera access
552
+ 4. **Try different browsers** (Chrome/Safari work best)
553
+ 5. **Close other camera apps** that might be using the camera
554
+
555
+ ### Issue: Touch/Tap Not Working (Mobile)
556
+
557
+ **Solutions:**
558
+
559
+ 1. **Clear browser cache** and reload
560
+ 2. **Disable browser zoom** if enabled
561
+ 3. **Try two-finger tap** if single tap doesn't work
562
+ 4. **Check touch targets** - buttons should be at least 44px
563
+ 5. **Restart browser app** on mobile device
564
+
565
+ ### Issue: Image Too Small/Large on Mobile
566
+
567
+ **Solutions:**
568
+
569
+ 1. **Portrait orientation** usually works better
570
+ 2. **Pinch to zoom** on images if needed
571
+ 3. **Landscape mode** available for wider screens
572
+ 4. **Image auto-resizes** based on screen size
573
+
574
+ ### Issue: Slow Performance on Mobile
575
+
576
+ **Solutions:**
577
+
578
+ 1. **Close other browser tabs** to free memory
579
+ 2. **Use smaller image files** (under 5MB recommended)
580
+ 3. **Ensure good network connection** for uploads
581
+ 4. **Clear browser cache** regularly
582
+ 5. **Restart browser** if app becomes unresponsive
583
+
584
+ ### Issue: Model Not Loading
585
+
586
+ **Solutions:**
587
+
588
+ 1. Verify model file exists: `models/1.h5`
589
+ 2. Install required packages:
590
+ ```bash
591
+ pip install tensorflow pillow flask
592
+ ```
593
+
594
+ ### Issue: JavaScript Errors
595
+
596
+ **Solutions:**
597
+
598
+ 1. Clear browser cache (Ctrl+F5)
599
+ 2. Check browser console (F12)
600
+ 3. Try a different browser
601
+ 4. Disable browser extensions
602
+
603
+ ### Issue: Image Not Displaying in Results
604
+
605
+ **Solutions:**
606
+
607
+ 1. Check browser network tab (F12) for failed requests
608
+ 2. Verify uploaded file in `static/uploads/` folder
609
+ 3. Check Flask console for file save errors
610
+
611
+ ## 🧪 Debug Features
612
+
613
+ ### Console Logging
614
+
615
+ The JavaScript includes extensive console logging. Open browser developer tools (F12) to see:
616
+
617
+ - File selection events
618
+ - Upload progress
619
+ - Server responses
620
+ - Error details
621
+
622
+ ### Debug Endpoints
623
+
624
+ - `/health` - System status
625
+ - `/debug/upload-test` - Upload directory test
626
+ - `/debug` - Interactive upload test page
627
+
628
+ ### Manual Testing
629
+
630
+ 1. **File Input Test**:
631
+
632
+ ```javascript
633
+ document.getElementById("fileInput").click();
634
+ ```
635
+
636
+ 2. **Check Selected File**:
637
+
638
+ ```javascript
639
+ console.log(selectedFile);
640
+ ```
641
+
642
+ 3. **Test FormData**:
643
+ ```javascript
644
+ const formData = new FormData();
645
+ formData.append("file", selectedFile);
646
+ console.log([...formData.entries()]);
647
+ ```
648
+
649
+ ## 💡 Tips for Success
650
+
651
+ 1. **Use supported image formats**: JPG, PNG, JPEG, GIF
652
+ 2. **Keep file size under 16MB**
653
+ 3. **Use clear potato leaf images**
654
+ 4. **Check browser compatibility** (modern browsers work best)
655
+ 5. **Enable JavaScript**
656
+ 6. **Allow camera permissions** (for camera capture feature)
657
+
658
+ ## 🆘 Getting Help
659
+
660
+ If upload functionality still doesn't work:
661
+
662
+ 1. **Check Flask console output** for error messages
663
+ 2. **Check browser console** (F12 → Console tab)
664
+ 3. **Try the debug page** at `/debug`
665
+ 4. **Test with different image files**
666
+ 5. **Restart the Flask app**
667
+ 6. **Check file permissions** on the upload directory
668
+
669
+ ## 🎯 Expected Results
670
+
671
+ After successful upload and analysis:
672
+
673
+ - Disease classification (Early Blight, Late Blight, or Healthy)
674
+ - ✅ Confidence percentage
675
+ - Treatment recommendations
676
+ - ✅ Analyzed image displayed in results
677
+ - Timestamp of analysis
678
+
679
+ # PDF Report Download Upgrade Guide
680
+
681
+ ## 🎉 New Features Added
682
+
683
+ ### **PDF Format**
684
+
685
+ - Professional PDF reports instead of simple text files
686
+ - Includes header, footer, tables, and proper formatting
687
+ - Company branding and professional layout
688
+
689
+ ### 📁 **Folder Selection**
690
+
691
+ - Choose where to save your PDF reports
692
+ - Modern file picker dialog (supported browsers)
693
+ - Automatic fallback to default downloads folder
694
+
695
+ ### 🎨 **Enhanced Report Content**
696
+
697
+ - **Report Header**: Timestamp, analysis method, model version
698
+ - **Analyzed Image**: Embedded image (if available)
699
+ - **Diagnosis Section**: Disease name, confidence, risk assessment
700
+ - **Probability Breakdown**: Table showing all class probabilities
701
+ - **Treatment Recommendations**: Numbered list of actionable advice
702
+ - **Professional Footer**: Branding and copyright information
703
+
704
+ ## 🚀 Installation Requirements
705
+
706
+ Add to your `requirements.txt`:
707
+
708
+ ```
709
+ reportlab>=4.0.0
710
+ ```
711
+
712
+ Install the new dependency:
713
+
714
+ ```bash
715
+ pip install reportlab>=4.0.0
716
+ ```
717
+
718
+ # PDF Generation Troubleshooting Guide
719
+
720
+ ## 🔧 If PDF Generation is Failing
721
+
722
+ ### Quick Fix Steps
723
+
724
+ 1. **Install ReportLab Library**
725
+
726
+ ```bash
727
+ pip install reportlab>=4.0.0
728
+ ```
729
+
730
+ 2. **Run Installation Script**
731
+
732
+ - **Windows**: Double-click `install_pdf_deps.bat`
733
+ - **Linux/Mac**: Run `bash install_pdf_deps.sh`
734
+
735
+ 3. **Restart the Application**
736
+ ```bash
737
+ python app.py
738
+ ```
739
+
740
+ ### Common Issues and Solutions
741
+
742
+ #### ❌ **"ReportLab not available" Error**
743
+
744
+ **Problem**: ReportLab library is not installed.
745
+
746
+ **Solution**:
747
+
748
+ ```bash
749
+ pip install reportlab
750
+ # or
751
+ pip install reportlab>=4.0.0
752
+ ```
753
+
754
+ **Alternative**: Use virtual environment
755
+
756
+ ```bash
757
+ python -m venv pdf_env
758
+ source pdf_env/bin/activate # Linux/Mac
759
+ # or
760
+ pdf_env\Scripts\activate # Windows
761
+ pip install reportlab
762
+ ```
763
+
764
+ #### **"Permission denied" or "Access denied" Errors**
765
+
766
+ **Problem**: Insufficient permissions to install packages.
767
+
768
+ **Solutions**:
769
+
770
+ 1. **Use --user flag**:
771
+
772
+ ```bash
773
+ pip install --user reportlab
774
+ ```
775
+
776
+ 2. **Run as administrator** (Windows):
777
+
778
+ - Right-click Command Prompt → "Run as administrator"
779
+ - Then run: `pip install reportlab`
780
+
781
+ 3. **Use sudo** (Linux/Mac):
782
+ ```bash
783
+ sudo pip install reportlab
784
+ ```
785
+
786
+ #### **"Module not found" Error Despite Installation**
787
+
788
+ **Problem**: ReportLab installed in different Python environment.
789
+
790
+ **Solutions**:
791
+
792
+ 1. **Check Python version**:
793
+
794
+ ```bash
795
+ python --version
796
+ which python # Linux/Mac
797
+ where python # Windows
798
+ ```
799
+
800
+ 2. **Install for specific Python version**:
801
+
802
+ ```bash
803
+ python3 -m pip install reportlab
804
+ # or
805
+ python3.9 -m pip install reportlab
806
+ ```
807
+
808
+ 3. **Verify installation**:
809
+ ```bash
810
+ python -c "import reportlab; print('ReportLab available')"
811
+ ```
812
+
813
+ #### ❌ **PDF Generation Works but Images Missing**
814
+
815
+ **Problem**: Image files not accessible or corrupted.
816
+
817
+ **Solutions**:
818
+
819
+ 1. **Check upload folder permissions**:
820
+
821
+ ```bash
822
+ ls -la static/uploads/ # Linux/Mac
823
+ dir static\uploads\ # Windows
824
+ ```
825
+
826
+ 2. **Verify image exists**:
827
+
828
+ - Check browser developer tools for 404 errors
829
+ - Ensure images are properly saved during upload
830
+
831
+ 3. **Check image format**:
832
+ - Ensure images are JPG, PNG, or supported formats
833
+ - ReportLab may have issues with some image formats
834
+
835
+ #### ❌ **Client-side PDF Generation Fails**
836
+
837
+ **Problem**: jsPDF library not loading.
838
+
839
+ **Solutions**:
840
+
841
+ 1. **Check internet connection** (jsPDF loads from CDN)
842
+
843
+ 2. **Check browser console** for JavaScript errors
844
+
845
+ #### **Folder Selection Not Working**
846
+
847
+ **Problem**: File System Access API not supported.
848
+
849
+ **Solutions**:
850
+
851
+ 1. **Update browser**:
852
+
853
+ - Chrome 86+ or Edge 86+ required for folder selection
854
+ - Firefox and Safari will use default download folder
855
+
856
+ 2. **Enable experimental features** (Chrome):
857
+
858
+ - Go to `chrome://flags`
859
+ - Enable "Experimental Web Platform features"
860
+
861
+ 3. **Accept automatic download** to default folder
862
+
863
+ The system should work with any clear image of a potato plant leaf!
864
+
865
+ ## 📄 License
866
+
867
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
868
+
869
+ ## 🙏 Acknowledgments
870
+
871
+ - **PlantVillage Dataset**: For providing the potato disease dataset
872
+ - **TensorFlow Team**: For the amazing deep learning framework
873
+ - **Open Source Community**: For inspiration and resources
874
+
875
+ ## 📞 Contact
876
+
877
+ - **Author**: Lucky Sharma
878
+ - **Email**: [email protected]
879
+ - **LinkedIn**: https://www.linkedin.com/in/lucky-sharma918894599977
880
+ - **GitHub**: https://github.com/itsluckysharma01
881
+
882
+ ---
883
+
884
+ <div align="center">
885
+ <p>⭐ Star this repository if you found it helpful!</p>
886
+ <p>🍀 Happy coding and may your potatoes be healthy!</p>
887
+ </div>
888
+ "