Loading... > nsfwjs项目地址:[infinitered/nsfwjs: NSFW detection on the client-side via TensorFlow.js (github.com)](https://github.com/infinitered/nsfwjs) ##### 官方服务demo ```javascript const express = require('express') const multer = require('multer') const jpeg = require('jpeg-js') const tf = require('@tensorflow/tfjs-node') const nsfw = require('../../dist') const app = express() const upload = multer() ... //以下省略 ``` ##### 常规使用,按照其官方的demo按照依赖模块,服务就跑起来了。 问题是其中一个依赖需要python环境,其一是麻烦,其二是怕影响生产环境,就想着在docker部署一个不是更好,找一下有没有已经有大佬做好轮子了,没有再自己搞,搜了一下还真有。 > [penndu/nsfw-api - Docker Image | Docker Hub](https://registry.hub.docker.com/r/penndu/nsfw-api/) 注意映射下80端口,比如`5050:80` ##### 测试服务 服务接收post请求,我们使用axios ```javascript const axios = require('axios').default const FormData = require('form-data'); const fs = require('fs') let config = { headers:{'Content-Type':'multipart/form-data'} }; let params = new FormData() ; //创建一个form对象 params.append('image',fs.createReadStream('./logo_li.png')); //append 向form表单添加数据 // 自行替换API地址 axios.post('http://127.0.0.1:5050/classify', params, config) .then( res => { console.log(res.data) }) ``` 此时返回结果 ```json { neutral: 0.9659328460693359, porn: 0.022903073579072952, drawing: 0.007416481617838144, hentai: 0.0021803502459079027, sexy: 0.0015672814333811402 } ``` 官方释义 ```plaintext The library categorizes image probabilities in the following 5 classes: Drawing - safe for work drawings (including anime) Hentai - hentai and pornographic drawings Neutral - safe for work neutral images Porn - pornographic images, sexual acts Sexy - sexually explicit images, not pornography ``` 数值越高,越接近 如果在lsky图床使用nsfwjs,接口处填入`http://127.0.0.1:5050/classify` 建议使用本地地址,防止服务滥用 *如果你想在另外一个跑客户端的docker里使用nsfwjs这个docker(比如我这个博客就是运行在群晖的docker中),在客户端的docker链接nsfwjs即可* 最后修改:2022 年 09 月 09 日 © 允许规范转载 打赏 赞赏作者 支付宝 赞 0 如果觉得我的文章对你有用,请随意赞赏
2 条评论
请教一下,使用axios接收post请求,是放在前端嘛?还是后端?还有一个问题是,axios.post('http://127.0.0.1:5050/classify', params, config)会导致跨域。
这个是测试服务是否正常的,一般docker起来了,直接把地址填入图床就行了。
不需要测试的话,仅有2步,部署docker => 在图床填入地址