diff --git a/packages/server/src/utils/is-nsfw/index.js b/packages/server/src/utils/is-nsfw/index.js new file mode 100644 index 00000000..a20c1b72 --- /dev/null +++ b/packages/server/src/utils/is-nsfw/index.js @@ -0,0 +1,23 @@ +const minumunPredictions = { + "Drawing": 0.8, + "Hentai": 0.8, + "Porn": 0.7, +} + +export default (predictions) => { + if (!Array.isArray(predictions)) { + throw new Error("predictions must be an array") + } + + let isNsfw = false + + Object.keys(minumunPredictions).forEach((key) => { + const prediction = predictions.find((prediction) => prediction.className === key) + + if (prediction && prediction.probability >= minumunPredictions[key]) { + isNsfw = true + } + }) + + return isNsfw +} \ No newline at end of file