Skip to content

Commit

Permalink
Merge pull request #34 from alexandrebedel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
alexandrebedel committed Apr 9, 2024
2 parents cfa0a07 + 2dcbefb commit b7d3502
Show file tree
Hide file tree
Showing 115 changed files with 27,328 additions and 2,485 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Runs the tests on every main push

on:
workflow_dispatch:
pull_request:
# branches:
# - develop

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: backend/package-lock.json
- name: Install modules and run tests
run: |
cd backend
npm ci
npm run test
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.keras
.idea

# Python venv
venv/

.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.DS_Store
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"vector": "cpp"
}
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ Here you can find the core source and documents of our "Smart Bin" project
[Overall documentation](./doc)

[API Documentation](http://localhost:3000/documentation)

# Getting started

To get started on this project please follow the READMEs on each parts of the project

[Setting up the AI](./ai/README.md)

[Setting up the backend](./backend/README.md)
34 changes: 34 additions & 0 deletions ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# AI project

This directory contains scripts and files related to the AI part of the ESP project. The main script, [predict.py](./predict.py), utilizes a pre-trained deep learning model to classify waste into various categories such as cardboard, glass, metal, paper, plastic, and trash. The model is provided in the file `trash_detection_model.keras` and the [dataset here](./dataset/).

## Installation

To set up the AI part, follow these steps:

1. Create and activate a virtual environment (optional but recommended):

```bash
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```

2. Install the required dependencies using pip:

```bash
pip install -r requirements.txt
```

3. Run the `predict.py` script to classify waste:

```bash
python predict.py path/to/your/image.jpg
```

4. Once you're done, deactivate the virtual environment:

```bash
deactivate
```

That's it! You have now successfully installed and used the waste detection system.
41 changes: 41 additions & 0 deletions ai/predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys
import os
import numpy as np
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import load_model

class_labels = ["cardboard", "glass", "metal", "paper", "plastic", "trash"]


def get_class(img_path: str, model) -> str:
img = image.load_img(img_path, target_size=(512, 384))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array /= 255.0 # Normalisation des pixels

# Prédiction de la classe
prediction = model.predict(img_array, verbose=0)
predicted_class = class_labels[np.argmax(prediction)]
if predicted_class in ["plastic", "cardboard", "paper"]:
return "recyclable"
if predicted_class == "glass":
return "glass"
if predicted_class == "trash":
return "trash"
return "error"


def main():
if len(sys.argv) != 2:
print("No such image found on the arguments list")
return -1

model = load_model(
os.path.dirname(os.path.abspath(__file__)) + "/trash_detection_model.keras"
)
print(get_class(sys.argv[1], model))
return 0


if __name__ == "__main__":
sys.exit(main())
3 changes: 3 additions & 0 deletions ai/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy
tensorflow
pillow
Binary file added ai/test-images/metal-can.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
375 changes: 0 additions & 375 deletions ai/trained-model.ipynb

This file was deleted.

687 changes: 687 additions & 0 deletions ai/training.ipynb

Large diffs are not rendered by default.

1,383 changes: 1,383 additions & 0 deletions ai/training2.ipynb

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
.next
*.swp
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
4 changes: 4 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.pnp
.pnp.js
.yarn/install-state.gz
postgres-data

# testing
/coverage
Expand Down Expand Up @@ -37,3 +38,6 @@ next-env.d.ts

# Smart Bin
/uploads

# Keep environment variables out of version control
.env
50 changes: 50 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM node:18-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

RUN mkdir .next
RUN chown nextjs:nodejs .next

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]
8 changes: 8 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Start Docker and Deploy Database

```bash
docker-compose up -d
npx prisma migrate dev
npx prisma generate
```

## Learn More

To learn more about Next.js, take a look at the following resources:
Expand Down
17 changes: 17 additions & 0 deletions backend/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/styles/globals.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/app/components",
"utils": "@/lib/utils"
}
}
24 changes: 24 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.1"

services:
# next:
# container_name: smart-bin
# build:
# context: .
# dockerfile: Dockerfile
# ports:
# - "3000:3000"
# depends_on:
# - db

db:
container_name: smart-bin-db
image: postgres:latest
restart: always
volumes:
- ./postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "5432:5432"
12 changes: 12 additions & 0 deletions backend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import nextJest from "next/jest";

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
})({
setupFilesAfterEnv: ["./jest.setup.ts"],
testEnvironment: "jest-environment-jsdom",
});

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig;
6 changes: 6 additions & 0 deletions backend/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Optional: configure or set up a testing framework before each test.
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`

// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";
6 changes: 4 additions & 2 deletions backend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {
output: "standalone",
};

module.exports = nextConfig
module.exports = nextConfig;
Loading

0 comments on commit b7d3502

Please sign in to comment.