NSFW Command with Tensorflow

This commit is contained in:
Dragon Fire
2021-03-22 17:23:12 -04:00
parent 9f3cd4d2db
commit d837eec501
6 changed files with 66 additions and 1 deletions
+8
View File
@@ -1,4 +1,5 @@
const crypto = require('crypto');
const tf = require('@tensorflow/tfjs-node');
const { decode: decodeHTML } = require('html-entities');
const { stripIndents } = require('common-tags');
const { URL } = require('url');
@@ -216,6 +217,13 @@ module.exports = class Util {
return str;
}
static isImageNSFW(model, image, bool = true) {
const img = await tf.node.decodeImage(new Uint8Array(image), 3);
const predictions = model.classify(image, 1);
img.dispose();
return bool ? predictions[0] !== 'Neutral' && predictions[0] !== 'Drawing' : predictions[0];
}
static async reactIfAble(msg, user, emoji, fallbackEmoji) {
const dm = !msg.guild;
if (fallbackEmoji && (!dm && !msg.channel.permissionsFor(user).has('USE_EXTERNAL_EMOJIS'))) {