forked from ZhuLinsen/daily_stock_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebui.py
More file actions
59 lines (44 loc) · 1.22 KB
/
webui.py
File metadata and controls
59 lines (44 loc) · 1.22 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
# -*- coding: utf-8 -*-
"""
===================================
WebUI 启动脚本
===================================
用于启动 Web 服务界面。
直接运行 `python webui.py` 将启动 Web 后端服务。
等效命令:
python main.py --webui-only
Usage:
python webui.py
WEBUI_HOST=0.0.0.0 WEBUI_PORT=8000 python webui.py
"""
from __future__ import annotations
import os
import logging
logger = logging.getLogger(__name__)
def main() -> int:
"""
启动 Web 服务
"""
# 兼容旧版环境变量名
host = os.getenv("WEBUI_HOST", os.getenv("API_HOST", "127.0.0.1"))
port = int(os.getenv("WEBUI_PORT", os.getenv("API_PORT", "8000")))
print(f"正在启动 Web 服务: http://{host}:{port}")
print(f"API 文档: http://{host}:{port}/docs")
print()
try:
import uvicorn
from src.config import setup_env
from src.logging_config import setup_logging
setup_env()
setup_logging(log_prefix="web_server")
uvicorn.run(
"api.app:app",
host=host,
port=port,
log_level="info",
)
except KeyboardInterrupt:
pass
return 0
if __name__ == "__main__":
raise SystemExit(main())