Skip to content

rishika0212/EcoSortAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EcoSortAI ♻️

A cross‑platform app that classifies waste using AI and helps users find nearby recycling centers.

Flutter Dart FastAPI Python TensorFlow License: MIT


🚀 Overview

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

🎬 Demo Screenshots

Homepage Recycling Centres

Points Page Facts Page


🏗️ Architecture

  • frontend/: Flutter app (UI, routing, services)
  • backend/: FastAPI service (auth, users, ML endpoints, SQLite)
  • ml/: Training, preprocessing, prediction, and exported models

Data Flow:

  1. User captures or picks an image in the app
  2. App sends the image to FastAPI /ml/predict
  3. Backend loads/uses exported model and returns label + confidence
  4. User actions can update points and badges via /points

🗂️ Project Structure

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

🏁 Quick Start

Prerequisites

  • Python 3.8+
  • pip
  • Flutter SDK (latest stable)
  • (Optional) CUDA for GPU acceleration

1) Backend Setup

  1. Navigate to backend directory:
    cd backend
  2. Create and activate a virtual environment (recommended):
    python -m venv .venv
    # Windows
    .venv\Scripts\activate
    # macOS/Linux
    source .venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Run the server:
    uvicorn app.main:app --host 0.0.0.0 --port 8000

2) Frontend Setup

  1. Navigate to frontend directory:
    cd frontend
  2. Install Flutter dependencies:
    flutter pub get
  3. 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";
    }
  4. Run the app:
    flutter run

🔌 API Reference (FastAPI)

Base URL: http://<server>:8000

Auth

  • 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)

Users

  • 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

Machine Learning

  • POST /ml/predict (multipart image upload)
    curl -X POST http://localhost:8000/ml/predict \
      -F "file=@/path/to/image.jpg"
    Response:
    {
      "label": "PET",
      "confidence": 0.94,
      "info": {}
    }

🤖 Machine Learning Details

  • Model: TensorFlow/Keras CNN.
  • Classes: PET, HDPE, LDPE, PP, PS.
  • Exported model path: ml/exported_model/ (used by backend).

Train

cd ml
python train.py

Predict locally

cd ml
python predict.py --image path/to/image.jpg

Export model for serving

cd ml
python export_model.py

�️ Database

  • Engine: SQLite
  • File: backend/backend/eco_sort_ai.db (auto-created)

🧪 Development Tips

  • 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

🩺 Troubleshooting

  • 401 Unauthorized: Ensure you pass Authorization: Bearer <token> from /auth/login.
  • Cannot reach backend: Set proper serverUrl in app_config.dart and ensure device/emulator can reach your machine’s IP.
  • Model errors: Make sure ml/exported_model/ exists and matches what predict.py expects.

🔐 Security Notes

  • 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.

🤝 Contributing

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

📄 License

MIT


👤 Authors

  • Rishika
  • Saurav Kumar

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published