rajkumarrawal's picture
Initial commit
2ec0d39
#!/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()