forked from FoundationAgents/OpenManus
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathweb_run.py
More file actions
57 lines (40 loc) · 1.5 KB
/
web_run.py
File metadata and controls
57 lines (40 loc) · 1.5 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
import argparse
import os
import sys
from pathlib import Path
import uvicorn
# 检查WebSocket依赖
def check_websocket_dependencies():
pass
return True
# 确保目录结构存在
def ensure_directories():
# 创建templates目录
templates_dir = Path("app/web/templates")
templates_dir.mkdir(parents=True, exist_ok=True)
# 创建static目录
static_dir = Path("app/web/static")
static_dir.mkdir(parents=True, exist_ok=True)
# 确保__init__.py文件存在
init_file = Path("app/web/__init__.py")
if not init_file.exists():
init_file.touch()
if __name__ == "__main__":
# 添加命令行参数
parser = argparse.ArgumentParser(description="OpenManus Web应用服务器")
parser.add_argument("--no-browser", action="store_true", help="启动时不自动打开浏览器")
parser.add_argument("--port", type=int, default=8000, help="服务器监听端口号 (默认: 8000)")
args = parser.parse_args()
ensure_directories()
if not check_websocket_dependencies():
print("退出应用。请安装必要的依赖后重试。")
sys.exit(1)
# 设置环境变量以控制是否自动打开浏览器
if args.no_browser:
os.environ["AUTO_OPEN_BROWSER"] = "0"
else:
os.environ["AUTO_OPEN_BROWSER"] = "1"
port = args.port
print(f"🚀 OpenManus Web 应用正在启动...")
print(f"访问 http://localhost:{port} 开始使用")
uvicorn.run("app.web.app:app", host="0.0.0.0", port=port, reload=True)