11 KiB
11 KiB
📋 API Classification - Implementation Summary
✅ Apa yang Telah Dibuat
Berikut adalah daftar lengkap file dan komponen yang telah dibuat untuk API klasifikasi model Anda:
🔌 Backend Components
1. Flask API Server (api_server.py)
- Location:
rice leaf diseases dataset/api_server.py - Fungsi: Server untuk menjalankan model TensorFlow
- Fitur:
- Load model dari
.keras,.h5, atau.json - Preprocess gambar input (224x224)
- Prediksi dengan confidence score
- Error handling
- CORS enabled untuk cross-origin requests
- Load model dari
2. Laravel Classification Controller (ClassificationController.php)
- Location:
web_TA/app/Http/Controllers/ClassificationController.php - Fungsi: Handle API requests dari client
- Endpoints:
POST /api/classification/classify- Analyze onlyPOST /api/classification/classify-and-save- Save imageGET /api/classification/test- Test connection
- Features:
- Validate image input
- Convert to base64
- Call Python API
- Store results
- Return disease information
3. API Routes (api.php)
- Location:
web_TA/routes/api.php - Fungsi: Define API endpoints
- Routes:
GET /api/classification/testPOST /api/classification/classifyPOST /api/classification/classify-and-save
🐍 Python Services
4. Requirements File (requirements_api.txt)
- Location:
rice leaf diseases dataset/requirements_api.txt - Content:
- TensorFlow 2.10+
- Flask + Flask-CORS
- OpenCV
- NumPy, Pandas
- Requests library
5. Database Models (models.py)
- Location:
rice leaf diseases dataset/models.py - Fungsi: SQLAlchemy model untuk classification history
- Fields:
- image_path, filename
- predicted_class, confidence
- all_predictions (JSON)
- disease_name, severity
- notes, timestamps
📱 Mobile Integration
6. Flutter Integration Guide (FLUTTER_INTEGRATION.md)
- Location:
FLUTTER_INTEGRATION.md - Content:
- ClassificationService class
- UI Screen component
- Image picker integration
- Result display
- Configuration guide
📚 Documentation
7. Setup Guide (SETUP_GUIDE.md)
- Location:
SETUP_GUIDE.md - Content:
- Step-by-step installation
- API endpoints documentation
- Troubleshooting guide
- Frontend examples
- Database setup
- Deployment notes
8. Quick Start (QUICK_START.md)
- Location:
QUICK_START.md - Content:
- 5-minute setup
- Quick endpoint reference
- Troubleshooting
- Next steps
9. Integration Summary (Dokumen ini)
- Location:
README_API.md - Content: Overview lengkap dari implementasi
🧪 Testing & Setup
10. Test Script (test_api.py)
- Location:
PROJECT TA/test_api.py - Fungsi:
- Test Python API health
- Test Laravel API connection
- Test image classification
- Detailed results reporting
11. Setup Scripts
- Windows:
setup.bat - Linux/Mac:
setup.sh - Fungsi: Automated setup verification
🎯 How It Works
User (Web/Mobile)
↓
[WEB UPLOAD] or [REST API]
↓
Laravel API (ClassificationController)
↓
[VALIDATION + ENCODING]
↓
Flask Python API Server
↓
[PREPROCESS + CNN MODEL]
↓
TensorFlow Model
↓
[PREDICTION RESULTS]
↓
Flask API
↓
[JSON RESPONSE]
↓
Laravel Controller
↓
[STORE RESULTS + ADD DISEASE INFO]
↓
JSON Response to User
📊 Supported Disease Classes
1. Bacterialblight (Bercak Bakteri)
- Confidence score + Symptoms + Treatment
2. Brownspot (Bercak Coklat)
- Confidence score + Symptoms + Treatment
3. Leafsmut (Jamur Daun)
- Confidence score + Symptoms + Treatment
🚀 Deployment Checklist
- Python API server running on port 5000
- Laravel server running on port 8000
- Model file exists (
.kerasor.h5) - Dependencies installed (
pip install -r requirements_api.txt) - Test API endpoints (
python test_api.py) - Database configured (MySQL)
- Storage directory writable
- CORS properly configured
- Environment variables set (
.env)
💾 Default Configurations
| Setting | Value | Location |
|---|---|---|
| Python API URL | http://127.0.0.1:5000 |
ClassificationController.php |
| Flask Port | 5000 |
api_server.py |
| Laravel Port | 8000 |
Default php artisan serve |
| Input Image Size | 224x224 |
api_server.py |
| Max Upload Size | 5MB |
ClassificationController.php |
| Classes | 3 (Bacterialblight, Brownspot, Leafsmut) | api_server.py |
🔄 Data Flow Example
Request:
POST /api/classification/classify
File: leaf_image.jpg
Processing:
- Laravel receives image
- Encodes to base64
- Sends to Python API
- Python loads model
- Preprocesses image (224x224, normalize)
- Runs prediction
- Returns class + confidence
Response:
{
"success": true,
"predicted_class": "Bacterialblight",
"confidence": 0.95,
"disease_info": {
"name": "Bercak Bakteri...",
"symptoms": [...],
"treatment": [...]
}
}
🛠️ Customization Options
Change API Port
Edit api_server.py:
app.run(host='127.0.0.1', port=5000) # Change port here
Change Input Image Size
Edit api_server.py:
IMG_SIZE = (224, 224) # Change size here
Add More Disease Classes
Update both files:
# api_server.py
CLASS_NAMES = ['Bacterialblight', 'Brownspot', 'Leafsmut', 'NewDisease']
// ClassificationController.php
private function getDiseaseInfo($className) { ... }
Increase Upload Size Limit
Edit ClassificationController.php:
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:10240' // 10MB
🔐 Security Notes
-
API Security:
- Add authentication token
- Rate limiting
- Input validation
- HTTPS in production
-
Model Security:
- Don't expose model file paths
- Validate image format
- Handle large files carefully
-
File Storage:
- Store outside public directory
- Implement cleanup policy
- Restrict file access
📞 Support Files
🎓 Architecture Diagram
┌─────────────────────────────────────────────────────────────┐
│ Client Application │
│ (Web Browser / Flutter Mobile) │
└────────────────────────┬────────────────────────────────────┘
│
│ HTTP Request
│ (POST with image)
↓
┌─────────────────────────────────────────────────────────────┐
│ Laravel Web Application │
│ (Port: 8000) │
├─────────────────────────────────────────────────────────────┤
│ ClassificationController │
│ ├─ /api/classification/classify │
│ ├─ /api/classification/classify-and-save │
│ └─ /api/classification/test │
└────────────────────────┬────────────────────────────────────┘
│
│ HTTP Request
│ (POST with base64)
↓
┌─────────────────────────────────────────────────────────────┐
│ Python Flask API Server │
│ (Port: 5000) │
├─────────────────────────────────────────────────────────────┤
│ /classify endpoint │
│ ├─ Decode image from base64 │
│ ├─ Preprocess (224x224, normalize) │
│ ├─ Load TensorFlow Model │
│ └─ Run prediction │
└────────────────────────┬────────────────────────────────────┘
│
│
↓
┌─────────────────────────────────────────────────────────────┐
│ TensorFlow/Keras CNN Model │
│ (rice_leaf_disease_model.keras) │
├─────────────────────────────────────────────────────────────┤
│ Input: 224x224x3 image │
│ Output: 3 class predictions with confidence │
│ Classes: [Bacterialblight, Brownspot, Leafsmut] │
└─────────────────────────────────────────────────────────────┘
🎯 Success Criteria
- ✅ API Server running without errors
- ✅ Model loads successfully
- ✅ Endpoints respond to requests
- ✅ Classification works with test images
- ✅ Results displayed correctly
- ✅ No CORS errors
- ✅ Image storage working
📈 Performance Notes
- Model Load Time: ~2-3 seconds (first request)
- Prediction Time: ~0.5-1 second per image
- Memory Usage: ~500MB (TensorFlow + Model)
- Network Latency: ~100-500ms (depends on connection)
Status: 🟢 Ready for Use
Last Updated: March 9, 2026
Version: 1.0