开源云开发流量主小程序-AI写诗-CitizenFour
项目名称:AI写诗
项目背景:每个人心目中都住着一个文艺青年,诗歌是人们的一种自然表达,它没有门槛,人人都是徐志摩
应用场景:可以写押韵自由诗、藏头诗、给定若干字作为主题的诗。生活中任何一件事都可以用诗去表达
目标用户:男女通吃,年龄18-40
实现思路:
1、文字安全识别
// 文字内容检测 async function msgSecCheck(event) { try { const res = await cloud.openapi.security.msgSecCheck({ content: event.content }) return res; } catch (err) { return err; } }
//文字检测页面调取 msgSecCheck(content) { wx.showLoading({ title: '检测文字中', mask:true }) // new Promise((resolve, reject)=>{ wx.cloud.callFunction({ name: 'contentCheck', data: { content: content, type: "msgSecCheck" }, success: res => { wx.hideLoading(); if (res.result.errCode == 0) { wx.navigateTo({ url: "../poem_detail/detail?type=" + app.globalData.e.type + "&text=" + content }); }else if (res.result.errCode == 87014) { wx.showToast({ title: '文字含有敏感违法内容!', icon: 'none' }); } }, fail: res => { wx.hideLoading(); } }) }
2、AI诗句学习搭建
搭建服务端API,服务器环境推荐:LNMP。解压server-api.zip到站点根目录。服务器安装python3和pip3。 python3.6+PIP3安装教程:https://www.cnblogs.com/yangzhaon/p/11203395.html 安装依赖:pip3 install tensorflow==1.14 word2vec numpy 搭建人工智能:解压好server-api.zip后,进入目录运行:python3 train.py,需要学习3把王者荣耀排位赛的时间 学习好之后,前台启动服务: python3 poem_server.py,可以看到只有本地+端口可以访问。 后台启动服务:nohup python3 poem_server.py >/dev/null 2>&1 & //如果要上线,请用后台启动服务命令,因为前台启动,一会儿就自动断开了 然后nginx做代理 location / { root html; proxy_pass http://127.0.0.1:5000; index index.html index.htm; } 这样,你就可以用域名访问你的服务端接口。然后把接口放到小程序前端需要修改的位置。 注:服务端为github开源,作者:norybaby,github地址:https://github.com/norybaby/poet
3、调取人工智能写诗API
由于本人考虑服务器安全性,故不开放api接口,自己根据第二步搭建好,替换下方【你的域名】
requestAI/index.js,第20行,替换【你的域名】,例如:mp.weixin.qq.com
async function requestAI(event){ try{ var options = { uri: "http://【你的域名】/poem?style="+ event.style +"&start=" + encodeURI(event.text), headers: { "Content-Type": "application/json" }, json: true }; return request(options) .then(function (res) { console.log(res,"请求获取成功"); return res; }) .catch(function (err) { console.log(err,'请求获取失败'); return err }); } catch (err) { return err; } }
架构图:
效果截图:
第三个图稍微有点出入,懒的改了
视频介绍:https://v.qq.com/x/page/r3153vkhuby.html
代码链接:https://citizenfour.coding.net/public/AIPoem/AIPoem/git
作品体验二维码:
团队简介:玩儿赚流量主,游走在骚操作的第一线。个人主页