Spaces:
Sleeping
Sleeping
Create lib/isporn.js
Browse files- 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;
|