A cross‑platform app that classifies waste using AI and helps users find nearby recycling centers.
EcoSortAI uses a TensorFlow/Keras CNN to classify plastic waste types from images and a Flutter app to deliver a clean, engaging experience. The FastAPI backend handles authentication, user points, leaderboards, and ML inference.
- AI waste classification: PET, HDPE, LDPE, PP, PS
- Recycling centers: View centers, materials they accept, and operating hours
- Gamification: Earn points and badges for recycling actions
- Cross‑platform: Android, iOS, Web, Windows, macOS, Linux
- frontend/: Flutter app (UI, routing, services)
- backend/: FastAPI service (auth, users, ML endpoints, SQLite)
- ml/: Training, preprocessing, prediction, and exported models
Data Flow:
- User captures or picks an image in the app
- App sends the image to FastAPI
/ml/predict
- Backend loads/uses exported model and returns label + confidence
- User actions can update points and badges via
/points
EcoSortAI/
├─ backend/
│ ├─ app/
│ │ ├─ auth/ # Auth routes, JWT, password hashing
│ │ ├─ users/ # User points, profile, leaderboard
│ │ ├─ ml_api/ # ML inference endpoint
│ │ ├─ database/ # SQLAlchemy models & session
│ │ └─ main.py # FastAPI app entry
│ └─ backend/eco_sort_ai.db# SQLite database (created at runtime)
├─ frontend/
│ └─ lib/ # Flutter code (config, screens, services)
├─ ml/
│ ├─ train.py # Training script
│ ├─ predict.py # Local prediction helper
│ ├─ export_model.py # Export model for serving
│ └─ exported_model/ # Saved model used by backend
└─ Images/ # Screenshots used in README
- Python 3.8+
- pip
- Flutter SDK (latest stable)
- (Optional) CUDA for GPU acceleration
- Navigate to backend directory:
cd backend
- Create and activate a virtual environment (recommended):
python -m venv .venv # Windows .venv\Scripts\activate # macOS/Linux source .venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Run the server:
uvicorn app.main:app --host 0.0.0.0 --port 8000
- Navigate to frontend directory:
cd frontend
- Install Flutter dependencies:
flutter pub get
- Configure API base URL in
frontend/lib/config/app_config.dart
:class AppConfig { // For Android emulator // static const String serverUrl = "http://10.0.2.2:8000"; // For localhost on desktop/iOS simulator // static const String serverUrl = "http://localhost:8000"; // For device on same LAN static const String serverUrl = "http://<YOUR_LOCAL_IP>:8000"; }
- Run the app:
flutter run
Base URL: http://<server>:8000
- POST
/auth/signup
curl -X POST http://localhost:8000/auth/signup \ -H "Content-Type: application/json" \ -d '{"username":"alice","email":"[email protected]","password":"secret"}'
- POST
/auth/login
→ returns{ access_token }
TOKEN=$(curl -s -X POST http://localhost:8000/auth/login \ -H "Content-Type: application/json" \ -d '{"username":"alice","password":"secret"}' | jq -r .access_token)
- GET
/users/me
(Bearer token required)curl -H "Authorization: Bearer $TOKEN" http://localhost:8000/users/me
- POST
/points
(awards points and updates badge)curl -X POST http://localhost:8000/points \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"plastic_type":"PET"}'
- GET
/leaderboard
curl -H "Authorization: Bearer $TOKEN" http://localhost:8000/leaderboard
- POST
/ml/predict
(multipart image upload)Response:curl -X POST http://localhost:8000/ml/predict \ -F "file=@/path/to/image.jpg"
{ "label": "PET", "confidence": 0.94, "info": {} }
- Model: TensorFlow/Keras CNN.
- Classes: PET, HDPE, LDPE, PP, PS.
- Exported model path:
ml/exported_model/
(used by backend).
cd ml
python train.py
cd ml
python predict.py --image path/to/image.jpg
cd ml
python export_model.py
- Engine: SQLite
- File:
backend/backend/eco_sort_ai.db
(auto-created)
- Hot reload (Flutter):
flutter run
and edit Dart files - Interactive docs (FastAPI): Open
http://localhost:8000/docs
- Testing auth quickly: Use a REST client (Insomnia/Postman) to store the Bearer token
- 401 Unauthorized: Ensure you pass
Authorization: Bearer <token>
from/auth/login
. - Cannot reach backend: Set proper
serverUrl
inapp_config.dart
and ensure device/emulator can reach your machine’s IP. - Model errors: Make sure
ml/exported_model/
exists and matches whatpredict.py
expects.
- JWT secret is currently in code for development. For production, load
SECRET_KEY
from environment variables and rotate regularly. - Validate and size-limit uploaded files for
/ml/predict
in production.
Pull requests are welcome. For major changes, please open an issue first to discuss the proposal.
- Fork the repo
- Create a feature branch
- Commit your changes
- Open a PR
MIT
- Rishika
- Saurav Kumar