mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Remove NSFWJS
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user