Skip to content

teleranek/teleranek.github.io

Repository files navigation

NSFW library - usage

In HTML, import library:

<script src="https://raw.githubusercontent.com/teleranek/teleranek.github.io/master/nsfwlib.js"></script>

Additionally, import script for caching resources to allow faster page opening. Download https://raw.githubusercontent.com/teleranek/teleranek.github.io/master/nsfw_cacher.js And put into script

<script src="nsfw_cacher.js"></script>

Initialize library:

let nsfw = new NSFWLib(true);

true indicates that we will use nsfw_cacher.js file, that needs to be put where index.html resides.

For monitoring load progress:

  1. Add progress bar and percent info box:
<div id="status"></div>
<div id="progress">
	<div id="progressBar"></div>
</div>
  1. Now you can set loading progress handler to indicate how much everything's loaded:
nsfw.setLoadProgressHandler(function (perc) {
	let percentage = perc + "%";
    progress.style.width = percentage;
    document.getElementById("status").innerText = `Loading: ${percentage}`;
});

Initialize and predict some photo:

nsfw._initialize().then(function() {
	var img = new Image();
	img.src = "IMAGE_URL";
	img.onload = function () {
		let is_this_nsfw = nsfw.predictSync(img);
		if (is_this_nsfw > 0.9) {
			console.log("THIS IMAGE IS NSFW!");
		}
	}
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published