Files
ailine/frontend/run.py
2026-04-21 16:27:05 +08:00

31 lines
926 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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()