Update jspp.js
This commit is contained in:
parent
77f9e6d525
commit
cd679dba4e
1 changed files with 24 additions and 2 deletions
26
jspp.js
26
jspp.js
|
@ -9,7 +9,28 @@ class JSPlusPlus {
|
|||
sleep(ms) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue