31 lines
926 B
Python
31 lines
926 B
Python
#!/usr/bin/env python3
|
||
"""
|
||
前端启动包装器
|
||
保持相对导入的同时,让 Streamlit 能正常运行
|
||
本地和容器环境使用相同的启动方式
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
|
||
# 添加项目根目录和 backend 目录到 Python 路径
|
||
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
backend_dir = os.path.join(project_root, "backend")
|
||
sys.path.insert(0, project_root)
|
||
sys.path.insert(0, backend_dir)
|
||
|
||
# 现在用正确的方式启动 Streamlit
|
||
# 我们不直接运行 frontend_main.py,而是先加载它作为模块
|
||
from streamlit.web import cli as stcli
|
||
|
||
# 设置工作目录到项目根
|
||
os.chdir(project_root)
|
||
|
||
# 构建 Streamlit 参数
|
||
frontend_main = os.path.join(project_root, "frontend", "src", "frontend_main.py")
|
||
sys.argv = ["streamlit", "run", frontend_main, "--server.port", "8501", "--server.address", "0.0.0.0"]
|
||
|
||
# 启动 Streamlit
|
||
if __name__ == "__main__":
|
||
stcli.main()
|