Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| 启动脚本 - 痞满症智能诊疗系统 | |
| 用于解决模块导入问题,并提供更好的启动体验 | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| # 添加项目根目录到 Python 路径 | |
| project_root = Path(__file__).parent | |
| if str(project_root) not in sys.path: | |
| sys.path.insert(0, str(project_root)) | |
| # 优先加载 .env 环境变量(若存在) | |
| try: | |
| from dotenv import load_dotenv | |
| env_path = project_root / ".env" | |
| load_dotenv(dotenv_path=env_path if env_path.exists() else None) | |
| except Exception: | |
| pass | |
| def main(): | |
| """主启动函数""" | |
| # 检查 API Key | |
| api_key = os.getenv("DEEPSEEK_API_KEY") | |
| # api_key = "sk-92205c60545442ceb773af800c2ba6ab" | |
| if not api_key: | |
| print("❌ 错误: 未找到 DEEPSEEK_API_KEY 环境变量") | |
| print("\n请先设置 API Key:") | |
| print("Windows PowerShell: $env:DEEPSEEK_API_KEY=\"your_api_key\"") | |
| print("Windows CMD: set DEEPSEEK_API_KEY=your_api_key") | |
| print("Linux/macOS: export DEEPSEEK_API_KEY=\"your_api_key\"") | |
| return 1 | |
| # 检查依赖 | |
| try: | |
| import fastapi | |
| import uvicorn | |
| import httpx | |
| import openai | |
| import sklearn | |
| except ImportError as e: | |
| print(f"❌ 错误: 缺少依赖包 {e}") | |
| print("\n请安装依赖:") | |
| print("pip install -r requirements.txt") | |
| return 1 | |
| print("🚀 启动痞满症智能诊疗系统...") | |
| print(f"📁 项目路径: {project_root}") | |
| print(f"🔑 API Key: {api_key[:4]}...") | |
| print(f"📖 API文档: http://localhost:8000/docs") | |
| print(f"❤️ 健康检查: http://localhost:8000/health") | |
| print(f"🖥️ 前端页面: http://localhost:8000/") | |
| print("\n按 Ctrl+C 停止服务器\n") | |
| # 导入并启动应用 | |
| try: | |
| import uvicorn | |
| uvicorn.run( | |
| "app.main:app", | |
| host="0.0.0.0", | |
| port=8000, | |
| reload=True, | |
| access_log=True | |
| ) | |
| except KeyboardInterrupt: | |
| print("\n👋 服务器已停止") | |
| return 0 | |
| except Exception as e: | |
| print(f"❌ 启动失败: {e}") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |