Files
BrunoGao 571c96f938 Initial commit: AI EMR Report Analysis System
- Complete FastAPI backend with OCR, rule engine, and LLM integration
- Vue3 frontend with TypeScript and Element Plus UI
- Medical rule engine with YAML configuration
- PaddleOCR for text extraction from PDFs and images
- Ollama LLM integration with template fallbacks
- Structured medical data parsing and standardization
- Dual-mode AI interpretation (patient & doctor versions)
- Background task processing with progress tracking
- Comprehensive documentation and setup scripts
2025-09-18 21:39:44 +08:00

164 lines
4.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""
启动脚本 - AI EMR Report Analysis System
"""
import os
import sys
import subprocess
from pathlib import Path
def check_requirements():
"""检查必要的依赖"""
try:
import uvicorn
import fastapi
import paddleocr
print("✅ Python依赖检查通过")
return True
except ImportError as e:
print(f"❌ 缺少Python依赖: {e}")
print("请运行: pip install -r requirements.txt")
return False
def check_ollama():
"""检查Ollama是否运行"""
try:
import httpx
response = httpx.get("http://localhost:11434/api/tags", timeout=5)
if response.status_code == 200:
print("✅ Ollama服务运行正常")
return True
else:
print("⚠️ Ollama服务未响应,将使用模板模式")
return False
except Exception:
print("⚠️ Ollama服务未启动,将使用模板模式")
return False
def setup_environment():
"""设置环境"""
# 创建必要的目录
dirs_to_create = ['uploads', 'static', 'logs']
for dir_name in dirs_to_create:
os.makedirs(dir_name, exist_ok=True)
print(f"✅ 创建目录: {dir_name}")
# 复制环境配置文件
if not os.path.exists('.env'):
if os.path.exists('.env.example'):
import shutil
shutil.copy('.env.example', '.env')
print("✅ 创建环境配置文件: .env")
else:
print("⚠️ .env.example文件不存在")
def run_backend():
"""启动后端服务"""
print("\n🚀 启动后端服务...")
# 确保在正确的目录中
os.chdir(Path(__file__).parent)
# 启动FastAPI服务
try:
import uvicorn
from app.main import app
uvicorn.run(
app,
host="0.0.0.0",
port=8000,
reload=True,
log_level="info"
)
except KeyboardInterrupt:
print("\n👋 后端服务已停止")
except Exception as e:
print(f"❌ 启动后端服务失败: {e}")
def run_frontend():
"""构建并启动前端"""
frontend_dir = Path(__file__).parent / "frontend"
if not frontend_dir.exists():
print("❌ 前端目录不存在")
return False
print("\n🔨 构建前端...")
# 检查Node.js
try:
subprocess.run(["node", "--version"], check=True, capture_output=True)
print("✅ Node.js已安装")
except (subprocess.CalledProcessError, FileNotFoundError):
print("❌ 请安装Node.js")
return False
# 切换到前端目录
os.chdir(frontend_dir)
try:
# 安装依赖
if not (frontend_dir / "node_modules").exists():
print("📦 安装前端依赖...")
subprocess.run(["npm", "install"], check=True)
# 构建前端
print("🔨 构建前端资源...")
subprocess.run(["npm", "run", "build"], check=True)
print("✅ 前端构建完成")
return True
except subprocess.CalledProcessError as e:
print(f"❌ 前端构建失败: {e}")
return False
except KeyboardInterrupt:
print("\n👋 前端构建已取消")
return False
def main():
"""主函数"""
print("=" * 50)
print("🏥 AI EMR Report Analysis System")
print("=" * 50)
# 检查系统要求
print("\n🔍 系统检查...")
if not check_requirements():
sys.exit(1)
check_ollama() # Ollama不是必需的,只是警告
# 设置环境
print("\n⚙️ 环境设置...")
setup_environment()
# 询问运行模式
print("\n🚀 选择运行模式:")
print("1. 仅后端 (开发模式)")
print("2. 构建前端 + 启动后端 (生产模式)")
print("3. 仅构建前端")
try:
choice = input("请选择 (1/2/3): ").strip()
if choice == "1":
run_backend()
elif choice == "2":
if run_frontend():
# 切换回根目录
os.chdir(Path(__file__).parent)
run_backend()
elif choice == "3":
run_frontend()
else:
print("无效选择")
except KeyboardInterrupt:
print("\n👋 再见!")
if __name__ == "__main__":
main()