File size: 9,998 Bytes
2ec0d39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env python3
"""
Setup script for Secure AI Agents Suite
Initializes the environment and prepares all components
"""

import os
import sys
import subprocess
import logging
from pathlib import Path


def setup_logging():
    """Set up logging for the setup process."""
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    )
    return logging.getLogger(__name__)


def check_python_version():
    """Check if Python version is compatible."""
    if sys.version_info < (3, 8):
        print("❌ Python 3.8 or higher is required")
        return False
    print(f"βœ… Python version: {sys.version}")
    return True


def install_dependencies():
    """Install required dependencies."""
    logger = logging.getLogger(__name__)
    
    logger.info("Installing dependencies from requirements.txt...")
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
        logger.info("βœ… Dependencies installed successfully")
        return True
    except subprocess.CalledProcessError as e:
        logger.error(f"❌ Failed to install dependencies: {e}")
        return False


def create_directories():
    """Create necessary directories."""
    logger = logging.getLogger(__name__)
    
    directories = [
        "logs",
        "data",
        "temp",
        "cache",
        "exports"
    ]
    
    for directory in directories:
        dir_path = Path(directory)
        dir_path.mkdir(exist_ok=True)
        logger.info(f"βœ… Created directory: {directory}")
    
    return True


def setup_configuration():
    """Set up configuration files."""
    logger = logging.getLogger(__name__)
    
    # Copy .env.example to .env if it doesn't exist
    env_example = Path(".env.example")
    env_file = Path(".env")
    
    if not env_file.exists() and env_example.exists():
        import shutil
        shutil.copy(env_example, env_file)
        logger.info("βœ… Created .env file from .env.example")
        logger.info("⚠️  Please update .env file with your API keys and configuration")
    elif env_file.exists():
        logger.info("βœ… .env file already exists")
    else:
        logger.warning("⚠️  No .env.example found to create .env file")
    
    return True


def create_launcher_scripts():
    """Create convenient launcher scripts."""
    logger = logging.getLogger(__name__)
    
    # Create launch script for all agents
    launch_script = """#!/bin/bash
# Secure AI Agents Suite Launcher

echo "πŸš€ Starting Secure AI Agents Suite..."
echo "Available agents:"
echo "  1. Enterprise Agent (Port 7860)"
echo "  2. Consumer Agent (Port 7861)" 
echo "  3. Creative Agent (Port 7862)"
echo "  4. Voice Agent (Port 7863)"
echo ""
read -p "Select agent to launch (1-4) or 'all': " choice

case $choice in
    1)
        echo "🏒 Starting Enterprise Agent..."
        python enterprise/enterprise_app.py
        ;;
    2)
        echo "πŸ‘₯ Starting Consumer Agent..."
        python consumer/consumer_app.py
        ;;
    3)
        echo "🎨 Starting Creative Agent..."
        python creative/creative_app.py
        ;;
    4)
        echo "🎀 Starting Voice Agent..."
        python voice/voice_app.py
        ;;
    all)
        echo "πŸš€ Starting all agents..."
        echo "⚠️  Note: This will try to start all agents simultaneously"
        echo "You may need to run them in separate terminals"
        echo ""
        echo "To start all agents, run these commands in separate terminals:"
        echo "  Terminal 1: python enterprise/enterprise_app.py"
        echo "  Terminal 2: python consumer/consumer_app.py"
        echo "  Terminal 3: python creative/creative_app.py"
        echo "  Terminal 4: python voice/voice_app.py"
        ;;
    *)
        echo "Invalid choice"
        ;;
esac
"""
    
    with open("launch_agents.sh", "w") as f:
        f.write(launch_script)
    
    # Make executable
    os.chmod("launch_agents.sh", 0o755)
    logger.info("βœ… Created launch script: launch_agents.sh")
    
    # Create Windows batch file
    batch_script = """@echo off
REM Secure AI Agents Suite Launcher

echo πŸš€ Starting Secure AI Agents Suite...
echo Available agents:
echo   1. Enterprise Agent (Port 7860)
echo   2. Consumer Agent (Port 7861)
echo   3. Creative Agent (Port 7862) 
echo   4. Voice Agent (Port 7863)
echo.
set /p choice="Select agent to launch (1-4) or 'all': "

if "%choice%"=="1" (
    echo 🏒 Starting Enterprise Agent...
    python enterprise/enterprise_app.py
) else if "%choice%"=="2" (
    echo πŸ‘₯ Starting Consumer Agent...
    python consumer/consumer_app.py
) else if "%choice%"=="3" (
    echo 🎨 Starting Creative Agent...
    python creative/creative_app.py
) else if "%choice%"=="4" (
    echo 🎀 Starting Voice Agent...
    python voice/voice_app.py
) else if "%choice%"=="all" (
    echo πŸš€ Starting all agents...
    echo ⚠️  Note: This will try to start all agents simultaneously
    echo You may need to run them in separate command prompts
    echo.
    echo To start all agents, run these commands in separate terminals:
    echo   Terminal 1: python enterprise/enterprise_app.py
    echo   Terminal 2: python consumer/consumer_app.py
    echo   Terminal 3: python creative/creative_app.py
    echo   Terminal 4: python voice/voice_app.py
) else (
    echo Invalid choice
)

pause
"""
    
    with open("launch_agents.bat", "w") as f:
        f.write(batch_script)
    
    logger.info("βœ… Created Windows launcher: launch_agents.bat")
    
    return True


def run_tests():
    """Run basic tests to ensure components work."""
    logger = logging.getLogger(__name__)
    
    logger.info("Running component tests...")
    
    # Test imports
    test_imports = [
        ("app_base", "Core application base"),
        ("mcp_client", "MCP client"),
        ("config_manager", "Configuration manager")
    ]
    
    for module_name, description in test_imports:
        try:
            __import__(module_name)
            logger.info(f"βœ… {description} - Import successful")
        except ImportError as e:
            logger.error(f"❌ {description} - Import failed: {e}")
            return False
    
    # Test agent imports
    agent_imports = [
        ("enterprise.enterprise_agent", "Enterprise Agent"),
        ("consumer.consumer_agent", "Consumer Agent"),
        ("creative.creative_agent", "Creative Agent"),
        ("voice.voice_agent", "Voice Agent")
    ]
    
    for module_name, description in agent_imports:
        try:
            __import__(module_name)
            logger.info(f"βœ… {description} - Import successful")
        except ImportError as e:
            logger.error(f"❌ {description} - Import failed: {e}")
            return False
    
    logger.info("βœ… All tests passed!")
    return True


def print_next_steps():
    """Print next steps for the user."""
    print("\n" + "="*60)
    print("πŸŽ‰ SECURE AI AGENTS SUITE SETUP COMPLETE!")
    print("="*60)
    
    print("\nπŸ“‹ Next Steps:")
    print("1. Update your .env file with API keys:")
    print("   β€’ OpenAI API key for GPT-4o integration")
    print("   β€’ Google API key for Gemini integration") 
    print("   β€’ ElevenLabs API key for voice synthesis")
    print("   β€’ Configure MCP server URLs (optional for demo)")
    
    print("\n2. Launch agents:")
    print("   β€’ Use the launcher script: ./launch_agents.sh (Linux/Mac)")
    print("   β€’ Or launch_agents.bat (Windows)")
    print("   β€’ Or run individual agents:")
    print("     - python enterprise/enterprise_app.py")
    print("     - python consumer/consumer_app.py")
    print("     - python creative/creative_app.py")
    print("     - python voice/voice_app.py")
    
    print("\n3. Access the web interfaces:")
    print("   β€’ Enterprise: http://localhost:7860")
    print("   β€’ Consumer:  http://localhost:7861")
    print("   β€’ Creative:  http://localhost:7862")
    print("   β€’ Voice:     http://localhost:7863")
    
    print("\n4. Deploy to production:")
    print("   β€’ Configure production MCP servers")
    print("   β€’ Set up Modal deployment for Voice Agent")
    print("   β€’ Deploy to Hugging Face Spaces")
    
    print("\nπŸ“š Documentation:")
    print("   β€’ README.md - Main documentation")
    print("   β€’ docs/ - Additional documentation")
    
    print("\nπŸ”§ Support:")
    print("   β€’ Check logs in logs/ directory")
    print("   β€’ Validate configuration with config_manager.py")
    print("   β€’ Run setup.py --test to verify installation")


def main():
    """Main setup function."""
    logger = setup_logging()
    
    print("πŸ”§ Secure AI Agents Suite - Setup Script")
    print("="*50)
    
    # Parse command line arguments
    if len(sys.argv) > 1 and sys.argv[1] == "--test":
        print("πŸ§ͺ Running tests only...")
        success = run_tests()
        sys.exit(0 if success else 1)
    
    # Setup steps
    steps = [
        ("Checking Python version", check_python_version),
        ("Installing dependencies", install_dependencies),
        ("Creating directories", create_directories),
        ("Setting up configuration", setup_configuration),
        ("Creating launcher scripts", create_launcher_scripts),
        ("Running tests", run_tests)
    ]
    
    success = True
    for step_name, step_func in steps:
        print(f"\nπŸ”„ {step_name}...")
        try:
            if not step_func():
                print(f"❌ {step_name} failed!")
                success = False
                break
        except Exception as e:
            print(f"❌ {step_name} failed with exception: {e}")
            success = False
            break
    
    if success:
        print("\nβœ… Setup completed successfully!")
        print_next_steps()
    else:
        print("\n❌ Setup failed! Please check the errors above.")
        sys.exit(1)


if __name__ == "__main__":
    main()