A machine learning-powered web application for detecting water quality using multiple ML algorithms. This system provides real-time water quality analysis through an intuitive web interface.
- Multiple ML Models: Random Forest, Neural Network, Decision Tree, KNN, and XGBoost
- Web Interface: User-friendly frontend for easy interaction
- Real-time Prediction: Instant water quality assessment
- Model Comparison: Compare different algorithms performance
- Data Upload: Support for CSV and Excel file uploads
- Dockerized: Easy deployment with Docker containers
├── backend/
│ ├── app.py # Flask API server
│ ├── ml_model/ # Pre-trained ML models
│ └── requirements.txt # Python dependencies
├── frontend/
│ ├── index.html # Main interface
│ ├── input.html # Data input page
│ ├── model.html # Model comparison
│ ├── result.html # Results display
│ └── assets/ # Static files
└── Dockerfile # Multi-stage Docker build
# Clone the repository
git clone https://github.com/suryangh/water-quality.git
cd water-quality
# Build Docker image
docker build -t water-quality .
# Run the application
docker run -d --name water-quality -p 5000:5000 -p 5500:5500 water-quality# Backend setup
cd backend
python -m venv dasildat
source dasildat/bin/activate # On Windows: dasildat\Scripts\activate
pip install -r requirements.txt
python app.py
# Frontend setup (in another terminal)
cd frontend
python serve_frontend.py- Frontend: http://localhost:5500
- Backend API: http://localhost:5000
The system analyzes the following water quality parameters:
| Parameter | Safe Range | Unit |
|---|---|---|
| Aluminium | 0 - 0.2 | mg/L |
| Ammonia | 0 - 0.5 | mg/L |
| Arsenic | 0 - 0.01 | mg/L |
| Barium | 0 - 2.0 | mg/L |
| Cadmium | 0 - 0.005 | mg/L |
| Chloramine | 0 - 4.0 | mg/L |
| Chromium | 0 - 0.1 | mg/L |
| Copper | 0 - 1.3 | mg/L |
| Fluoride | 0 - 4.0 | mg/L |
| Bacteria | 0 | count |
| Viruses | 0 | count |
- Random Forest - General purpose, robust predictions
- Neural Network - Complex pattern recognition
- Decision Tree - Simple, interpretable rules
- K-Nearest Neighbors (KNN) - Pattern-based classification
- XGBoost - High-performance gradient boosting
- All models are pre-trained on water quality datasets
- Real-time inference with optimized prediction times
- Model comparison features available in the web interface
POST /predict
Content-Type: application/json
{
"model": "random_forest",
"features": {
"Aluminium": 0.1,
"Ammonia": 0.2,
"Arsenic": 0.005,
// ... other parameters
}
}{
"prediction": "Safe",
"confidence": 0.95,
"model_used": "random_forest",
"analysis": {
"safe_parameters": ["Aluminium", "Ammonia"],
"unsafe_parameters": ["Arsenic"]
}
}The system supports uploading water quality data in:
- CSV format
- Excel (.xlsx, .xls) format
Upload files through the web interface for batch predictions.
Image Size: ~560MB (optimized with multi-stage build)
Container Specifications:
- Base: Python 3.12 Alpine Linux
- Multi-stage build for minimal size
- Non-root user for security
- Exposed ports: 5000 (API), 5500 (Frontend)
- Python 3.12+
- Docker (optional)
- Git
# Clone repository
git clone https://github.com/suryangh/water-quality.git
cd water-quality
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r backend/requirements.txt
# Run in development mode
cd backend
python app.pyFLASK_ENV=production # Flask environment
PYTHONUNBUFFERED=1 # Python output buffering
PYTHONDONTWRITEBYTECODE=1 # Disable .pyc files- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Team DASILDAT -
If you have any questions or issues, please:
- Check the Issues page
- Create a new issue if your problem isn't already reported
- Provide detailed information about your setup and the issue