Update jspp.js

This commit is contained in:
Sam Sneed 2024-05-31 20:31:27 +00:00 committed by GitHub
parent 77f9e6d525
commit cd679dba4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

24
jspp.js
View file

@ -10,6 +10,27 @@ class JSPlusPlus {
return new Promise(resolve => setTimeout(resolve, ms));
}
function isToxic(sentences) {
let gen = new JSPlusPlus.General
// Load the model. Users optionally pass in a threshold and an array of
// labels to include.
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs")
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity")
let threshold = 0.9;
let toxic = false
toxicity.load(threshold).then(model => {
model.classify(sentences).then(predictions => {
predictions.forEach(classified => {
if (classified.label == "toxicity") {
toxic = classified.results.match
}
});
});
});
return toxic
}
async asyncSleep(ms) {
await new Promise(r => setTimeout(r, ms));
}
@ -728,7 +749,8 @@ class JSPlusPlus {
initGun(relays = []) {
JSPlusPlus.General.require("https://cdn.jsdelivr.net/npm/gun/gun.js")
let gen = new JSPlusPlus.General
gen.require("https://cdn.jsdelivr.net/npm/gun/gun.js")
return Gun(relays)
}
}