Files
ai_coding/README.md
2026-01-30 18:20:43 +08:00

146 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CardioAI - 心血管疾病智能辅助系统
CardioAI 是一个多模块智能辅助系统,集成了数据可视化、机器学习预测和 AI 语音问答功能,旨在为心血管疾病的预防和管理提供科学支持。
## 项目结构
```
D:\AI_Coding
├── data/ # 数据文件目录
│ └── 心血管疾病.xlsx # 心血管疾病数据集
├── module1_dashboard/ # 数据可视化模块
│ └── cardio_dashboard.py # Streamlit 应用
├── module2_predictor/ # 机器学习预测模块
│ ├── templates/ # 前端模板
│ │ └── index.html # 预测界面
│ ├── app.py # Flask API 后端
│ ├── train_and_save.py # 模型训练脚本
│ └── cardio_predictor_model.pkl # 训练好的模型
├── module3_voice_assistant/ # AI 语音问答模块
│ ├── templates/ # 前端模板
│ │ └── voice_index.html # 语音助手界面
│ └── voice_assistant_app.py # Flask 后端
├── aicodes/ # 参考代码和配置
│ ├── .env # 环境变量配置
│ ├── llm_streaming.py # LLM 流式调用示例
│ └── 语音合成CosyVoice.md # 语音合成参考文档
├── requirements.txt # 项目依赖
└── README.md # 项目说明文档
```
## 环境配置
### 1. 创建并激活 Conda 虚拟环境
```bash
# 创建虚拟环境
conda create -n cardioenv python=3.10
# 激活虚拟环境
conda activate cardioenv
```
### 2. 安装依赖
```bash
pip install -r requirements.txt
```
### 3. 配置环境变量
`aicodes/.env` 文件中配置以下环境变量:
```env
# DeepSeek API 配置
DEEPSEEK_API_KEY1=your_deepseek_api_key
base_url1=https://api.deepseek.com/v1
# DashScope API 配置 (用于 CosyVoice)
DASHSCOPE_API_KEY=your_dashscope_api_key
```
## 模块启动方法
### 1. 数据可视化模块 (Streamlit)
```bash
# 在项目根目录执行
streamlit run module1_dashboard/cardio_dashboard.py
```
访问地址:`http://localhost:8501`
### 2. 机器学习预测模块 (Flask)
#### 第一步:训练模型
```bash
# 在项目根目录执行
python module2_predictor/train_and_save.py
```
#### 第二步:启动 API 服务
```bash
# 在项目根目录执行
python module2_predictor/app.py
```
访问地址:`http://localhost:5000`
### 3. AI 语音问答模块 (Flask)
```bash
# 在项目根目录执行
python module3_voice_assistant/voice_assistant_app.py
```
访问地址:`http://localhost:5001`
## 功能说明
### 数据可视化模块
- 数据清洗和特征工程
- 交互式数据筛选(年龄、性别、疾病状态)
- 年龄分布和 BMI 类别对心血管疾病影响的可视化
- 实时数据统计和风险率计算
### 机器学习预测模块
- 基于 XGBoost 的心血管疾病预测
- 完整的特征预处理 pipeline
- 实时预测 API 接口
- 用户友好的预测表单界面
### AI 语音问答模块
- 集成 DeepSeek 大模型作为专业心血管健康顾问
- 使用 CosyVoice 实现文字到语音的转换
- 语音自动播放功能
- 专业的心血管健康知识问答
## 技术栈
- **数据处理**Pandas, NumPy, Scikit-learn
- **机器学习**XGBoost, Joblib
- **数据可视化**Streamlit, Plotly Express
- **Web 框架**Flask
- **大模型**DeepSeek (LangChain)
- **语音合成**CosyVoice (DashScope)
- **环境管理**Conda, Python-dotenv
## 注意事项
1. 确保已配置正确的 API Key 才能使用 AI 语音问答功能
2. 数据文件 `心血管疾病.xlsx` 必须存在于 `data/` 目录中
3. 首次运行机器学习预测模块时需要先训练模型
4. 所有模块需要在激活的 `cardioenv` 虚拟环境中运行
## 项目维护
- **数据更新**:可直接替换 `data/心血管疾病.xlsx` 文件
- **模型更新**:重新运行 `train_and_save.py` 脚本
- **依赖更新**:修改 `requirements.txt` 文件后重新安装
## 许可证
本项目仅供学习和研究使用。