-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_app.py
More file actions
124 lines (106 loc) · 3.36 KB
/
start_app.py
File metadata and controls
124 lines (106 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
"""
BINGO知识之象 启动脚本
启动服务并自动打开浏览器
"""
import os
import sys
import time
import webbrowser
import subprocess
from pathlib import Path
def check_requirements():
"""检查依赖是否已安装"""
try:
import fastapi
import uvicorn
import pydantic
print("✅ 基础依赖检查通过")
return True
except ImportError as e:
print(f"❌ 缺少依赖: {e}")
print("请运行: pip install -r requirements.txt")
return False
def check_python_version():
"""检查Python版本"""
if sys.version_info < (3, 9):
print("❌ Python版本过低,需要Python 3.9+")
print(f"当前版本: {sys.version}")
return False
print(f"✅ Python版本检查通过: {sys.version}")
return True
def setup_environment():
"""设置环境"""
# 确保在正确的目录
script_dir = Path(__file__).parent
os.chdir(script_dir)
# 检查配置目录
config_dir = Path("config")
if not config_dir.exists():
config_dir.mkdir(exist_ok=True)
print("✅ 创建配置目录")
# 检查静态文件目录
for dir_name in ["static", "templates", "styles"]:
dir_path = Path(dir_name)
if not dir_path.exists():
dir_path.mkdir(exist_ok=True)
print(f"✅ 创建{dir_name}目录")
def start_server():
"""启动服务器"""
try:
print("\n🚀 正在启动BINGO知识之象...")
print("📍 服务地址: http://127.0.0.1:8000")
print("⚙️ 配置界面: http://127.0.0.1:8000#config")
print("📖 项目文档: 查看README.md和TODO.md")
print("\n💡 提示: 按Ctrl+C停止服务")
print("-" * 50)
# 延迟2秒后打开浏览器
def open_browser():
time.sleep(2)
try:
webbrowser.open("http://127.0.0.1:8000")
print("🌐 已在默认浏览器中打开应用")
except Exception as e:
print(f"⚠️ 无法自动打开浏览器: {e}")
print("请手动访问: http://127.0.0.1:8000")
# 在新线程中打开浏览器
import threading
browser_thread = threading.Thread(target=open_browser)
browser_thread.daemon = True
browser_thread.start()
# 启动服务器
import uvicorn
uvicorn.run(
"app:app",
host="127.0.0.1",
port=8000,
reload=True,
log_level="info",
access_log=True
)
except KeyboardInterrupt:
print("\n\n👋 BINGO知识之象已停止运行")
print("感谢使用!")
except Exception as e:
print(f"\n❌ 启动失败: {e}")
print("请检查错误信息并重试")
def main():
"""主函数"""
print("=" * 60)
print("🎨 BINGO知识之象 (BINGO Knowledge Visualization)")
print(" 基于AI的知识可视化平台")
print("=" * 60)
# 环境检查
if not check_python_version():
return False
if not check_requirements():
return False
# 环境设置
setup_environment()
# 启动服务器
start_server()
return True
if __name__ == "__main__":
success = main()
if not success:
sys.exit(1)