Skip to content

Commit 911af81

Browse files
author
Max
committed
First commit
0 parents  commit 911af81

23 files changed

+22894
-0
lines changed

.eslintrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"extends": [
3+
"airbnb"
4+
],
5+
"env": {
6+
"browser": true,
7+
"jest": true,
8+
"es6": true,
9+
"node": true
10+
},
11+
"plugins": [
12+
"react-hooks"
13+
],
14+
"parserOptions": {
15+
"requireConfigFile": false,
16+
"parser": "@babel/eslint-parser"
17+
},
18+
"rules": {
19+
"linebreak-style": 0,
20+
"react/jsx-one-expression-per-line": 0,
21+
"import/no-extraneous-dependencies": [
22+
"error",
23+
{
24+
"devDependencies": true
25+
}
26+
],
27+
"react-hooks/rules-of-hooks": "error",
28+
"react-hooks/exhaustive-deps": "warn",
29+
"react/function-component-definition": [
30+
2,
31+
{
32+
"namedComponents": "arrow-function",
33+
"unnamedComponents": "arrow-function"
34+
}
35+
]
36+
}
37+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
node_modules
3+
backend/uploads

MLJavascript.code-workspace

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {
8+
"editor.formatOnSave": true,
9+
"javascript.format.enable": false,
10+
"eslint.alwaysShowStatus": true,
11+
"editor.codeActionsOnSave": {
12+
"source.fixAll.eslint": true,
13+
"source.fixAll.stylelint": true
14+
},
15+
"stylelint.validate": [
16+
"css",
17+
"less",
18+
"postcss",
19+
"scss"
20+
]
21+
}
22+
}

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ML Javascript
2+
3+
Small javascript client server for Machine Learning example with TensorFlow.js (`#MadeWithTFJS`)
4+
5+
## How to run
6+
7+
Define an `.env` file with the environment variables `http_proxy` and `https_proxy`
8+
9+
docker-compose up
10+
11+
Enjoy on:
12+
13+
http://localhost:3000/

backend/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
uploads

backend/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:14.17.0
2+
3+
COPY package* .
4+
5+
RUN npm ci
6+
7+
COPY . .
8+

backend/backend.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const express = require('express');
2+
const multer = require('multer');
3+
const fs = require('fs');
4+
const cors = require('cors');
5+
6+
const app = express();
7+
8+
app.use(cors());
9+
10+
const PORT = 5000;
11+
12+
const FilesFolder = 'uploads';
13+
const FileModel = 'model.json';
14+
const FileModelWeights = 'model.weights.bin';
15+
16+
const storage = multer.diskStorage({
17+
destination(req, file, callback) {
18+
if (!fs.existsSync(FilesFolder)) {
19+
fs.mkdirSync(FilesFolder);
20+
}
21+
callback(null, FilesFolder);
22+
},
23+
filename(req, file, callback) {
24+
callback(null, file.fieldname);
25+
},
26+
});
27+
const upload = multer({ storage });
28+
29+
app.post('/uploadModel', upload.fields([{
30+
name: FileModel, maxCount: 1,
31+
}, {
32+
name: FileModelWeights, maxCount: 1,
33+
}]), (req, res, next) => {
34+
const { complete } = req;
35+
if (!complete) {
36+
const error = new Error('Error during upload');
37+
error.httpStatusCode = 400;
38+
return next(error);
39+
}
40+
return res.send(complete);
41+
});
42+
43+
app.get('/downloadModel', (req, res) => {
44+
const file = `${FilesFolder}/${FileModel}`;
45+
res.download(file);
46+
});
47+
48+
app.get('/downloadModelWeight', (req, res) => {
49+
const file = `${FilesFolder}/${FileModelWeights}`;
50+
res.download(file);
51+
});
52+
53+
54+
app.listen(PORT, () => {
55+
// eslint-disable-next-line no-console
56+
console.info(`Backend ready on port ${PORT}`);
57+
});

0 commit comments

Comments
 (0)