-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (23 loc) · 775 Bytes
/
index.js
File metadata and controls
30 lines (23 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const express = require('express')
const multer = require('multer')
const tf = require('@tensorflow/tfjs-node')
const nsfw = require('nsfwjs')
const app = express()
const upload = multer()
let _model
app.post('/api', upload.single('image'), async (req, res) => {
if (!req.file) res.status(400).send('Missing image multipart/form-data')
else {
const image = await tf.node.decodeImage(req.file.buffer)
const predictions = await _model.classify(image)
image.dispose()
res.json(predictions)
}
})
app.get('/', async (req, res) => {
res.send('PornChecker API - From Gfriends Project');
})
const load_model = async () => {
_model = await nsfw.load('file://./model/', { size: 224 })
}
load_model().then(() => app.listen(process.env.PORT || 5000))