Remove NSFWJS

This commit is contained in:
lilyissillyyy
2026-02-17 17:38:40 -05:00
parent 183424e081
commit d83a1fb2b9
8 changed files with 3 additions and 93 deletions
-24
View File
@@ -1,5 +1,4 @@
const tf = require('@tensorflow/tfjs-node');
const nsfw = require('nsfwjs');
const faceDetection = require('@tensorflow-models/face-detection');
const faceModel = faceDetection.SupportedModels.MediaPipeFaceDetector;
const path = require('path');
@@ -9,18 +8,11 @@ module.exports = class Tensorflow {
constructor(client) {
Object.defineProperty(this, 'client', { value: client });
this.nsfwjs = null;
this.faceDetector = null;
this.styleModel = null;
this.transformerModel = null;
}
async loadNSFWJS() {
const nsfwjs = await nsfw.load('MobileNetV2');
this.nsfwjs = nsfwjs;
return this.nsfwjs;
}
async loadFaceDetector() {
const faceDetector = await faceDetection.createDetector(faceModel, { runtime: 'tfjs', maxFaces: 10 });
this.faceDetector = faceDetector;
@@ -55,22 +47,6 @@ module.exports = class Tensorflow {
return faces;
}
async isImageNSFW(image, bool = true) {
const img = await tf.node.decodeImage(image, 3);
const predictions = await this.nsfwjs.classify(img);
img.dispose();
if (bool) {
const results = [];
results.push(predictions[0]);
for (const result of predictions) {
if (result.className === predictions[0].className) continue;
if (result.probability >= predictions[0].probability - 0.1) results.push(result);
}
return results.some(result => result.className !== 'Drawing' && result.className !== 'Neutral');
}
return predictions;
}
async stylizeImage(image, styleImg) {
const imageTensor = await tf.node.decodeImage(image, 3);
const [originalHeight, originalWidth] = imageTensor.shape.slice(0, 2);