容器处理

This commit is contained in:
2026-04-21 16:27:05 +08:00
parent 8b354b7ccc
commit 08826c70a3
13 changed files with 80 additions and 220 deletions

30
frontend/run.py Normal file
View File

@@ -0,0 +1,30 @@
#!/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()

View File

@@ -1,4 +1,5 @@
"""
UI 组件模块
包含所有可复用的 Streamlit 组件
"""
"""

View File

@@ -6,18 +6,25 @@ AI Agent 前端主入口
import sys
import os
# 添加项目根目录到 Python 路径,支持绝对导入
# 现在的结构: frontend/src/frontend_main.py所以要获取 frontend/ 目录作为根
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# 添加当前目录到路径,确保智能导入能工作
src_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, src_dir)
import streamlit as st
# 使用相对导入
from .config import config
from .state import AppState
from .components.sidebar import render_sidebar
from .components.chat_area import render_chat_area
from .components.info_panel import render_info_panel
# 智能导入:作为 __main__ 被 Streamlit 运行时用绝对导入,否则用相对导入
if __name__ == '__main__':
from config import config
from state import AppState
from components.sidebar import render_sidebar
from components.chat_area import render_chat_area
from components.info_panel import render_info_panel
else:
from .config import config
from .state import AppState
from .components.sidebar import render_sidebar
from .components.chat_area import render_chat_area
from .components.info_panel import render_info_panel
# =============================================================================