/ashiley-neural-network

Ashiley is an open project aiming to perform the classification of images and texts with ML 100% in Javascript. Every system runs under Node.js and the Adonis.js framework along with Google's TensorFlow.js. The entire system was designed not to rely on a database.

Primary LanguageJavaScript

ASHILEY NEURAL-NETWORK

License: MIT version

alt text

Ashiley is an open project aiming to perform the classification of images and texts with ML 100% in Javascript. Every system runs under Node.js and the Adonis.js framework along with Google's TensorFlow.js.

The entire system was designed not to rely on a database. All templates and files are stored in binaries or .txt

This project aims to prevent inappropriate or vulgar photos from being inserted into our system, so racist, malicious and inappropriate descriptions or texts are posted in our environment.

We can also use Ashiley to validate specific systems. For example ... If you have a car sales website, you can train our AI to only accept pictures of cars, thus avoiding problems with other types of ads.

I tried to develop our system in the simplest and most usual way possible. My purpose is that you just train and make requests, so you don't have to worry about writing any lines of code.

alt text

1 Installation

git clone 
cd ashiley-neural-network
npm install
adonis serve --dev

2.1 how to train - photos

All training documents are located inside the public folder.

For photo training you must create the directories inside public / train so that the photos start exactly as the folder name + the number (if it is less than 10 it must contain the zero to the left). After inserting the correctly named photos you must go to the Controller BrainController and in the constant className insert the name of the new training class into the array In this version only JPG formats are allowed.

  • photo training routes
    GET: trainRGB -> Training based on RGB color scale. It is advisable to use it for comparison and color
    classification, such as a can of coca-cola

    GET: trainContour -> Training based on color scale and photo outlines. In this training, resizing takes place of pictures

    GET: trainNeuralNetWork -> ML-based training with Google's TensorFlow. Level of accuracy very high.

2.2 how to train - text

For training and classification of texts Ashiley has two forms of treatment. ML and Naive Bayes Classification. With this training our AI will be able to classify text with racist, extremist or improper content.

Within the Helpers / Helpers.js file there is a method that returns an object array that expects a type and set of phrases related to this model.

  • text training routes

    GET: trainText -> ML-based training with google's tensorFlow.js.

    GET: trainNavy -> Training based on the NavyBaiers Algorithm

3 How to use

  • image classification routes
    METHOD: POST Ashiley hopes to receive a formData with an image file from nom "image" that must have a maximum of 2mb and be in JPG format.

  • text classification routes
    METHOD: POST At this point Ashiley hopes to receive a text in an http request. The name of the text field must be "text" and does not have a pre-set size or character limit.

4 production environment

To run our AI in a production environment to validate our images and texts, we follow the steps below:

initially install PM2:

npm install pm2 -g

All right, now we must configure our AI. Our .env file must have the following characteristics

HOST=0.0.0.0
PORT=3333
NODE_ENV=production 
APP_URL=http://${HOST}:${PORT}
CACHE_VIEWS=false
APP_KEY=DgtuWIF6DlJq1UK4NjPlqwecPCzbvbfm

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_DATABASE=adonis

SESSION_DRIVER=cookie
HASH_DRIVER=bcrypt

Now we are going to generate a new APP_KEY for our AI (in the future it will be used for authentication on our system).

 adonis key:generate

Okay, now it's time to get our AI to run. Within the root folder of the system, execute the command:

pm2 start server.js --name

Now run the command to see if everything is running:

pm2 list

All right, now just start validating the images and texts sent to your system

5 Authentication system

When you run the command:

 adonis key:generate

a key is generated within our .env and we will use that key to authenticate requests.

In the header of your request, place Authorization as the same value generated in your APP_KEY.

In this way we guarantee that you will be the only one to use all the routes in the system, since two equal keys are not generated.

When the route is triggered, our Middleware goes into action and checks ... If the flow is authorized, the flow is normal, if a 401 error is not returned.