Description
CDN Search
75CDN jsDelivr
<!DOCTYPE html>
<html lang="zh-cn">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>NSFWJS 鉴黄</title>

	<!-- TensorFlow.js -->
	<script src="https://code.bdstatic.com/npm/@tensorflow/tfjs@1.7.4/dist/tf.min.js"></script>
	<!-- Load the NSFWJS library -->
	<script src="https://code.bdstatic.com/npm/@nsfw-filter/nsfwjs@2.2.0/dist/nsfwjs.min.js"></script>
</head>

<body>
	<input type="file" onchange="showImg()" accept="image/*">
	<button onclick="judge()">鉴别</button><br>
	<img id="myImg" src="https://api.zme.ink/svg/200*200" alt="Thumb preview...">
	<pre id='pr'></pre>
</body>

</html>
function judge() {
    const img = document.getElementById('myImg')

    nsfwjs.load('https://code.bdstatic.com/npm/nsfwjs-node@2.1.14/model/').then(function (model) {
        model.classify(img).then(function (predictions) {
            console.log(predictions)
            document.getElementById('pr').innerHTML = JSON.stringify(predictions, null, 4);
        })
    })
}

function showImg() {
    var demoImage = document.querySelector('img');
    var file = document.querySelector('input[type=file]').files[0];
    var reader = new FileReader();
    reader.onload = function () {
        demoImage.src = reader.result;
    }
    reader.readAsDataURL(file);
    console.log(file)
}
img {
    max-width: 300px;
    max-height: 300px;
}