Rewrite how tensorflow works

This commit is contained in:
Dragon Fire
2024-05-01 01:08:33 -04:00
parent 2bd3f6fcc6
commit 857105ac88
14 changed files with 81 additions and 80 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ module.exports = class FacesCommand extends Command {
async run(msg, { image }) {
const imgData = await request.get(image);
const faces = await this.client.detectFaces(imgData.body);
const faces = await this.client.tensorflow.detectFaces(imgData.body);
if (!faces) return msg.reply('There are no faces in this image.');
if (faces === 'size') return msg.reply('This image is too large.');
const base = await loadImage(imgData.body);
+8 -2
View File
@@ -1,5 +1,11 @@
const Command = require('../../framework/Command');
const request = require('node-superfetch');
let parseDomain;
let ParseResultType;
import('parse-domain').then(loadedModule => {
parseDomain = loadedModule.parseDomain;
ParseResultType = loadedModule.ParseResultType;
});
module.exports = class IsItDownCommand extends Command {
constructor(client) {
@@ -26,8 +32,8 @@ module.exports = class IsItDownCommand extends Command {
}
async run(msg, { url }) {
const { type, domain, topLevelDomains } = this.client.parseDomain(url.hostname);
if (type !== this.client.ParseResultType.Listed) return msg.reply('This domain is not supported.');
const { type, domain, topLevelDomains } = parseDomain(url.hostname);
if (type !== ParseResultType.Listed) return msg.reply('This domain is not supported.');
const { text } = await request
.post('https://www.isitdownrightnow.com/check.php')
.query({ domain: `${domain}.${topLevelDomains.join('.')}` });
+1 -2
View File
@@ -1,7 +1,6 @@
const Command = require('../../framework/Command');
const request = require('node-superfetch');
const { stripIndents } = require('common-tags');
const { isImageNSFW } = require('../../util/Util');
const displayNames = {
Drawing: 'SFW (Drawing)',
Neutral: 'SFW',
@@ -33,7 +32,7 @@ module.exports = class NsfwImageCommand extends Command {
async run(msg, { image }) {
const { body } = await request.get(image);
const predictions = await isImageNSFW(this.client.nsfwModel, body, false);
const predictions = await this.client.tensorflow.isImageNSFW(body, false);
const formatted = predictions.map(result => {
const percentage = Math.round(result.probability * 100);
return `${percentage}% ${displayNames[result.className]}`;
+2 -2
View File
@@ -1,7 +1,7 @@
const Command = require('../../framework/Command');
const { PermissionFlagsBits } = require('discord.js');
const request = require('node-superfetch');
const { isImageNSFW, isUrlNSFW } = require('../../util/Util');
const { isUrlNSFW } = require('../../util/Util');
module.exports = class ScreenshotCommand extends Command {
constructor(client) {
@@ -41,7 +41,7 @@ module.exports = class ScreenshotCommand extends Command {
}
const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${url.href}`);
if (!msg.channel.nsfw) {
const aiDetect = await isImageNSFW(this.client.nsfwModel, body);
const aiDetect = await this.client.tensorflow.isImageNSFW(body);
if (aiDetect) return msg.reply('This site isn\'t NSFW, but the resulting image was.');
}
return msg.say({ files: [{ attachment: body, name: 'screenshot.png' }] });
+1 -1
View File
@@ -28,7 +28,7 @@ module.exports = class AnimeEyesCommand extends Command {
const leftEye = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'anime-eyes', 'left.png'));
const rightEye = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'anime-eyes', 'right.png'));
const imgData = await request.get(image);
const faces = await this.client.detectFaces(imgData.body);
const faces = await this.client.tensorflow.detectFaces(imgData.body);
if (!faces) return msg.reply('There are no faces in this image.');
if (faces === 'size') return msg.reply('This image is too large.');
const base = await loadImage(imgData.body);
+1 -1
View File
@@ -34,7 +34,7 @@ module.exports = class DannyDevitoCommand extends Command {
async run(msg, { image }) {
const danny = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'danny-devito.png'));
const imgData = await request.get(image);
const faces = await this.client.detectFaces(imgData.body);
const faces = await this.client.tensorflow.detectFaces(imgData.body);
if (!faces) return msg.reply('There are no faces in this image.');
if (faces === 'size') return msg.reply('This image is too large.');
const base = await loadImage(imgData.body);
+1 -1
View File
@@ -41,7 +41,7 @@ module.exports = class EmojiFaceCommand extends Command {
const emojiData = await request.get(emojiURL);
const emojiImg = await loadImage(emojiData.body);
const imgData = await request.get(image);
const faces = await this.client.detectFaces(imgData.body);
const faces = await this.client.tensorflow.detectFaces(imgData.body);
if (!faces) return msg.reply('There are no faces in this image.');
if (faces === 'size') return msg.reply('This image is too large.');
const base = await loadImage(imgData.body);
+1 -1
View File
@@ -26,7 +26,7 @@ module.exports = class EyesCommand extends Command {
async run(msg, { image }) {
const eyes = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'eyes.png'));
const imgData = await request.get(image);
const faces = await this.client.detectFaces(imgData.body);
const faces = await this.client.tensorflow.detectFaces(imgData.body);
if (!faces) return msg.reply('There are no faces in this image.');
if (faces === 'size') return msg.reply('This image is too large.');
const base = await loadImage(imgData.body);
+1 -1
View File
@@ -34,7 +34,7 @@ module.exports = class ShrekCommand extends Command {
async run(msg, { image }) {
const shrek = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'shrek.png'));
const imgData = await request.get(image);
const faces = await this.client.detectFaces(imgData.body);
const faces = await this.client.tensorflow.detectFaces(imgData.body);
if (!faces) return msg.reply('There are no faces in this image.');
if (faces === 'size') return msg.reply('This image is too large.');
const base = await loadImage(imgData.body);