File size: 3,565 Bytes
adec1cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
"""
多模态智能体系统启动脚本
"""
import os
import sys
import argparse
from pathlib import Path

# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from config import Config

def check_environment():
    """检查运行环境"""
    print("🔍 检查运行环境...")
    
    # 检查Python版本
    if sys.version_info < (3, 8):
        print("❌ Python版本过低,需要Python 3.8+")
        return False
    
    print(f"✅ Python版本: {sys.version}")
    
    # 检查必要的环境变量
    if not Config.validate():
        print("❌ 环境变量配置不完整")
        print("请设置以下环境变量:")
        print("  - OPENAI_API_KEY")
        return False
    
    print("✅ 环境变量配置正确")
    
    # 检查依赖包
    try:
        import torch
        import transformers
        import langchain
        import langgraph
        import gradio
        print("✅ 核心依赖包已安装")
    except ImportError as e:
        print(f"❌ 缺少依赖包: {e}")
        print("请运行: pip install -r requirements.txt")
        return False
    
    return True

def run_web_interface():
    """运行Web界面"""
    print("🌐 启动Web界面...")
    from app import demo
    demo.launch(debug=Config.DEBUG, share=False)

def run_test():
    """运行测试"""
    print("🧪 运行系统测试...")
    from test_agent import main as test_main
    test_main()

def run_interactive():
    """运行交互式模式"""
    print("💬 启动交互式模式...")
    from app import MultiModalAgent
    
    agent = MultiModalAgent()
    print("智能体已初始化,输入 'quit' 退出")
    
    while True:
        try:
            question = input("\n请输入问题: ").strip()
            if question.lower() in ['quit', 'exit', 'q']:
                break
            
            if not question:
                continue
            
            print("🤖 正在处理...")
            answer = agent(question)
            print(f"回答: {answer}")
            
        except KeyboardInterrupt:
            print("\n👋 再见!")
            break
        except Exception as e:
            print(f"❌ 错误: {str(e)}")

def main():
    """主函数"""
    parser = argparse.ArgumentParser(description="多模态智能体系统")
    parser.add_argument(
        "--mode", 
        choices=["web", "test", "interactive"], 
        default="web",
        help="运行模式: web(Web界面), test(测试), interactive(交互式)"
    )
    parser.add_argument(
        "--debug", 
        action="store_true",
        help="启用调试模式"
    )
    
    args = parser.parse_args()
    
    # 设置调试模式
    if args.debug:
        os.environ["DEBUG"] = "True"
        os.environ["LOG_LEVEL"] = "DEBUG"
    
    print("🚀 多模态智能体系统")
    print("=" * 40)
    
    # 检查环境
    if not check_environment():
        sys.exit(1)
    
    # 打印配置
    Config.print_config()
    
    # 根据模式运行
    try:
        if args.mode == "web":
            run_web_interface()
        elif args.mode == "test":
            run_test()
        elif args.mode == "interactive":
            run_interactive()
    except KeyboardInterrupt:
        print("\n👋 程序被用户中断")
    except Exception as e:
        print(f"❌ 运行错误: {str(e)}")
        if Config.DEBUG:
            import traceback
            traceback.print_exc()

if __name__ == "__main__":
    main()