26-7-31-1

This commit is contained in:
shuai
2026-07-31 12:27:41 +08:00
commit 9b8b8b57b3
142 changed files with 22408 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
# Smart Hospital AI Service
FastAPI 微服务:YOLO 影像检测(演示级)+ MONAI/OpenCV 预处理 + LangChain RAG + 报告/决策生成。
兼容 **DeepSeek / Qwen** 等 OpenAI 协议大模型。
## 快速启动
```bash
cd ai-service
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
# source .venv/bin/activate
# CPU 版 torch(体积更小,实训推荐)
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements.txt
copy .env.example .env # 按需填写 LLM_API_KEY
uvicorn app.main:app --host 0.0.0.0 --port 8001
```
> `.venv` 可随时删除后按上面步骤重建;权重见 `data/weights/`(已精简保留医学检测模型)。
- 文档:http://127.0.0.1:8001/docs
- 健康检查:http://127.0.0.1:8001/health
## 主要接口
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/health` | 服务与能力探测 |
| POST | `/imaging/analyze` | 影像 YOLO 检测 + 初步诊断/报告 |
| POST | `/report/decision` | EMR 辅助决策(护理/治疗/随访 + RAG) |
| POST | `/report/imaging` | 单独生成影像报告 |
| POST | `/rag/query` | 知识库问答 |
| POST | `/rag/ingest` | 追加知识文档 |
## 环境变量(`.env`)
| 变量 | 说明 | 默认 |
|------|------|------|
| `DEMO_MODE` | `demo` / `real` / `auto` | `auto` |
| `YOLO_WEIGHTS` | YOLO 权重路径 | 空则演示检测 |
| `LLM_BASE_URL` | OpenAI 兼容地址 | `https://api.deepseek.com` |
| `LLM_API_KEY` | API Key | 空则模板/RAG 摘要 |
| `LLM_MODEL` | 模型名 | `deepseek-chat` |
## 可选视觉栈
```bash
pip install torch torchvision ultralytics monai
```
安装后将 `YOLO_WEIGHTS` 指向权重文件,并设 `DEMO_MODE=auto` 或 `real`。
## 与 Spring Boot 对接
业务后端配置(`application.yml`):
```yaml
ai:
service:
enabled: true
base-url: http://127.0.0.1:8001
```
前端仍只访问 Spring Boot `:8080`,由后端转发到本服务。
## 声明
输出仅供教学实训与辅助决策演示,**不能替代执业医师诊断**。