An API for MagicBrain, a modern web application which identifies faces in images and display its boundaries.
Explore the docs »
API in Production
·
Report Bug / Request Feature
Table of Contents
Back-End API for MagicBrain, a modern web application which identifies faces in images and display its boundaries.
This project was originally built as part of a Full Stack pratical exercise, aimed at learning how to build a REST API using Javascript, Node and Express and PostgreSQL database.
MagicBrain API was built with the following technologies:
To get a local copy up and running follow these simple example steps.
Have npm
installed in your machine.
- npm
npm install npm@latest -g
- Clarifai API Key -> Get yours HERE
- Postgres installed and running locally -> Download it HERE
On terminal
-
Clone the repo
git clone https://github.com/sgtbrunner/magicbrain-api
-
Navigate to project folder
cd magicbrain-api
-
Install NPM packages
npm install
-
Create a local postgres database
createdb 'your-database'
-
Inside your newly created database, add two tables with the following scripts:
CREATE TABLE users { id serial PRIMARY KEY, name VARCHAR(100), email text UNIQUE NOT NULL, entries BIGINT DEFAULT, joined TIMESTAMP NOT NULL };
and
CREATE TABLE login { id serial PRIMARY KEY, hash varchar(100) NOT NULL, email text UNIQUE NOT NULL };
-
Create a
config.js
file in the project root folder and export yourAPI KEY
:const API_KEY = // your api key module.exports = { API_KEY, }
-
Setup your personal database info in
database.js
as:const DEV_DB_CONNECTION = { host: '127.0.0.1', user: '', // your master local db user name password: '', // the local database password database: 'your-database', // the local dabatase name }
The MagicBrain API doesn't have authentication.
Run the following commands on terminal within the project folder:
- Starting the app
The project should be served at:
npm run start:dev
Alternatively, you can try out the API in PRODUCTION:http://localhost:5000/
https://mighty-beyond-04256.herokuapp.com
GET /
Input: No Input for this endpoint
Output: server is working!!!!
GET /profile/{id}
Input:
- id: user's id
Output:
{
"id": 2,
"name": "test",
"email": "test@test.com",
"entries": "1",
"joined": "2021-05-18T01:18:12.131Z"
}
Errors:
"HTTP ERROR STATUS 404 - User id 1 not found"
POST /signin
Body Input:
{
"email": "test@email.com",
"password": "testtest"
}
Output:
{
"id": 20,
"name": "test",
"email": "test@email.com",
"entries": "11",
"joined": "2021-05-18T01:18:12.131Z"
}
Errors:
{
"error": "You have entered an invalid username and/or password"
}
POST /register
Body Input:
{
"name": "test",
"email": "admin@test.com",
"password": "fasfasf56"
}
Output:
{
"id": 5,
"name": "test",
"email": "admin@test.com",
"entries": "0",
"joined": "2021-08-13T15:17:00.125Z"
}
Errors:
{
"error": "Email \"admin@test.com\" already registered."
}
POST /register
Body Input:
{
"name": "test",
"email": "admin@test.com",
"password": "fasfasf56"
}
Output:
{
"id": 5,
"name": "test",
"email": "admin@test.com",
"entries": "0",
"joined": "2021-08-13T15:17:00.125Z"
}
Errors:
{
"error": "Email \"admin@test.com\" already registered."
}
PUT /image
Body Input:
{
"id": "5",
}
Output:
{
"count": 6,
}
Errors:
{
"error": "Unable to update your image count. Please try again later"
}
POST /imageurl
Body Input:
{
"input": "https://www.aceshowbiz.com/images/photo/the_rock.jpg"
}
Output:
{
"status": {
"code": 10000,
"description": "Ok",
"req_id": "32736d634ba346df81879affa5fb5daa"
},
"outputs": [
{
"id": "af88b1bb78014896b0bcbc6d5273e117",
"status": {
"code": 10000,
"description": "Ok"
},
"created_at": "2021-08-13T16:46:05.322537140Z",
"model": {
"id": "a403429f2ddf4b49b307e318f00e528b",
"name": "face",
"created_at": "2016-10-25T19:30:38.541073Z",
"app_id": "main",
"output_info": {
"output_config": {
"concepts_mutually_exclusive": false,
"closed_environment": false,
"max_concepts": 0,
"min_value": 0
},
"message": "Show output_info with: GET /models/{model_id}/output_info",
"type": "detect-concept",
"type_ext": "detect-concept"
},
"model_version": {
"id": "34ce21a40cc24b6b96ffee54aabff139",
"created_at": "2019-01-17T19:45:49.087547Z",
"status": {
"code": 21100,
"description": "Model is trained and ready"
},
"visibility": {
"gettable": 10
},
"app_id": "main",
"user_id": "clarifai",
"metadata": {}
},
"display_name": "Face Detection",
"user_id": "clarifai",
"input_info": {},
"train_info": {},
"model_type_id": "visual-detector",
"visibility": {
"gettable": 10
},
"metadata": {}
},
"input": {
"id": "2b660a8308a944e5a75a2d96806985fe",
"data": {
"image": {
"url": "https://www.aceshowbiz.com/images/photo/the_rock.jpg"
}
}
},
"data": {
"regions": [
{
"id": "b055216dba030ca1944c06937ccdadd6",
"region_info": {
"bounding_box": {
"top_row": 0.05029705,
"left_col": 0.32780963,
"bottom_row": 0.6298665,
"right_col": 0.7165285
}
},
"data": {
"concepts": [
{
"id": "ai_8jtPl3Xj",
"name": "face",
"value": 0.99990416,
"app_id": "main"
}
]
},
"value": 0.99990416
}
]
}
}
],
"rawData": {
"status": {
"code": 10000,
"description": "Ok",
"req_id": "32736d634ba346df81879affa5fb5daa"
},
"outputs": [
{
"id": "af88b1bb78014896b0bcbc6d5273e117",
"status": {
"code": 10000,
"description": "Ok"
},
"created_at": "2021-08-13T16:46:05.322537140Z",
"model": {
"id": "a403429f2ddf4b49b307e318f00e528b",
"name": "face",
"created_at": "2016-10-25T19:30:38.541073Z",
"app_id": "main",
"output_info": {
"output_config": {
"concepts_mutually_exclusive": false,
"closed_environment": false,
"max_concepts": 0,
"min_value": 0
},
"message": "Show output_info with: GET /models/{model_id}/output_info",
"type": "detect-concept",
"type_ext": "detect-concept"
},
"model_version": {
"id": "34ce21a40cc24b6b96ffee54aabff139",
"created_at": "2019-01-17T19:45:49.087547Z",
"status": {
"code": 21100,
"description": "Model is trained and ready"
},
"visibility": {
"gettable": 10
},
"app_id": "main",
"user_id": "clarifai",
"metadata": {}
},
"display_name": "Face Detection",
"user_id": "clarifai",
"input_info": {},
"train_info": {},
"model_type_id": "visual-detector",
"visibility": {
"gettable": 10
},
"metadata": {}
},
"input": {
"id": "2b660a8308a944e5a75a2d96806985fe",
"data": {
"image": {
"url": "https://www.aceshowbiz.com/images/photo/the_rock.jpg"
}
}
},
"data": {
"regions": [
{
"id": "b055216dba030ca1944c06937ccdadd6",
"region_info": {
"bounding_box": {
"top_row": 0.05029705,
"left_col": 0.32780963,
"bottom_row": 0.6298665,
"right_col": 0.7165285
}
},
"data": {
"concepts": [
{
"id": "ai_8jtPl3Xj",
"name": "face",
"value": 0.99990416,
"app_id": "main"
}
]
},
"value": 0.99990416
}
]
}
}
]
}
}
Errors:
{
"error": "Unable to detect faces on selected image. Please check your url and try again."
}
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Guilherme Brunner - guilherme.brunner@gmail.com
Project Link: https://github.com/sgtbrunner/magicbrain-api