autotagger v2 lol

This commit is contained in:
Flummi
2022-05-05 16:02:17 +02:00
parent 72267a8740
commit 7d49a0ce52
4 changed files with 131 additions and 37 deletions

View File

@@ -1,7 +1,9 @@
import crypto from "crypto";
import util from "util";
import db from "./sql.mjs";
import { exec as _exec } from "child_process";
const exec = util.promisify(_exec);
const scrypt = util.promisify(crypto.scrypt);
const epochs = [
@@ -150,5 +152,31 @@ export default new class {
}
return tags;
};
async detectNSFW(dest) {
const { stdout, stderr } = await exec(
`python -c "import sys\nfrom nsfw_detector import predict\nmodel = predict.load_model('./nsfw_model.h5')\nprint(predict.classify(model, './public/b/${dest}'))"`
);
const res = JSON.parse(stdout.replace(/\'/g, '"').split('\n').slice(1, -1));
const tmp = Object.values(res)[0];
tmp.sexy = tmp.sexy / 2;
let nsfw = false;
if(tmp.neutral >= .7)
nsfw = false;
else if((tmp.sexy + tmp.porn + tmp.hentai) >= .7)
nsfw = true;
else if(tmp.drawings >= .4)
nsfw = false;
else
nsfw = false;
return {
isNSFW: nsfw,
score: tmp.sexy + tmp.porn + tmp.hentai,
scores: tmp
};
};
};