caliphdev commited on
Commit
54645b7
1 Parent(s): eaada9a

Create lib/isporn.js

Browse files
Files changed (1) hide show
  1. lib/isporn.js +17 -0
lib/isporn.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const tf = require('@tensorflow/tfjs-node');
2
+ const nsfw = require('nsfwjs');
3
+
4
+ async function fn(buffer) {
5
+ const model = await nsfw.load();
6
+ const image = await tf.node.decodeImage(buffer,3)
7
+ const predictions = await model.classify(image)
8
+ image.dispose();
9
+ return predictions.map(item => {
10
+ return {
11
+ type: item.className,
12
+ probability: (item.probability * 100).toFixed(2)
13
+ }
14
+ });
15
+ }
16
+
17
+ module.exports = fn;