# 通过中文姓名预测性别 **Repository Path**: deng-yongsheng/gender-predict ## Basic Information - **Project Name**: 通过中文姓名预测性别 - **Description**: 通过中文姓名预测性别,基于keras,flask,vue,bootstrap - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 3 - **Created**: 2022-05-30 - **Last Updated**: 2024-02-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 通过中文姓名预测性别 ## 项目地址 在线服务地址: [通过中文姓名预测性别-邓永盛](http://genderpredict.dengyongsheng.cn/) http://genderpredict.dengyongsheng.cn/ + 浏览器端效果: ![Screenshot_2](./preview/Screenshot_2.jpg) ## 项目技术栈 基于Keras和flask和jQuery和BootStrap和MySQL的 ### AI预测 + 从mysql数据库中加载数据集 + 汉字转词向量 + one-hot硬编码 + 词嵌入 + 一维卷积 ### 后端 + Flask,跨域,路由,jinja2模板 + 持久化 + 基于sqlalchemy的对象关系映射(ORM) + mysql + 部署 + 基于docker的容器化 + nginx基于域名的转发 + https证书配置 ### 前端 + node + Vue3 + Bootstrap5 + axios ## 项目部署 你可以将代码和模型克隆到本地,部署自己的server ### 创建`db.ini`文件 系统会将用户请求记录到mysql数据库中。项目启动还依赖一个`db.ini`文件,这里没有上传到git,文件内容为: ```ini [db] server = localhost user = * passwd = * name = * ``` ### 安装依赖 ```shell python3 -m pip install requirements.txt ``` ### 直接启动 ```shell python main.py ``` ### docker + 生成镜像 ```shell docker build -t gender-predict . ``` + 生成并启动docker容器 ```shell docker run -itd --name gender-predict -p 8080:8080 gender-predict ``` ## 网络模型 ```text Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= embedding (Embedding) (None, 5, 4) 40928 conv1d (Conv1D) (None, 3, 3) 39 conv1d_1 (Conv1D) (None, 2, 9) 63 flatten (Flatten) (None, 18) 0 dense (Dense) (None, 1) 19 ================================================================= Total params: 41,049 Trainable params: 41,049 Non-trainable params: 0 _________________________________________________________________ ``` ## 项目依赖 ### python依赖 ```text Flask==2.1.2 Flask_SQLAlchemy==2.5.1 keras==2.8.0 numpy==1.22.3 SQLAlchemy==1.4.7 ``` ### npm依赖 前端页面已经编译发布,不需要安装前端依赖了,这里只是说明依赖项 ```javascript "dependencies": { "@popperjs/core": "^2.11.5", "axios": "^0.27.2", "bootstrap": "^5.1.3", "core-js": "^3.8.3", "popper.js": "^1.16.1", "vue": "^3.2.13" } ``` ## API访问 ### python ```python import requests res = requests.post('http://genderpredict.dengyongsheng.cn/', json={'name': '邓永盛'}).text print(res.json()) ``` ### javascript ```javascript import axios from 'axios'; axios.post('http://genderpredict.dengyongsheng.cn/',{name: name}).then(res => { console.log(res); }) ``` ## 项目日志 + `2021年10月29日` 完成了第一个可用版本 + `2021年11月30日` 将模型输入从one-hot硬编码转换为嵌入层词向量,提高了模型的训练效率 + `2022年1月9日` 从jinja2模板的大后端,改为加入了vue的伪前后端分离,只有首次请求为后端渲染,提高了后续的 + `2022年3月14日` 优化了模型,将参数数量从`3,127,457`个减少到`41,049`个 + `2022年5月23日` 添加dockerfile,支持docker部署。从伪前后端分离改为前后端分离,使用bootstrap5 + vue + axios