#!/bin/bash # RPA Vision V3 - Chef d'Orchestre ๐ŸŽผ # Auteur: Dom, Alice Kiro - 15 dรฉcembre 2024 # Lance et orchestre tous les composants du systรจme RPA Vision V3 set -e # Exit on error # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' PURPLE='\033[0;35m' BOLD='\033[1m' NC='\033[0m' # No Color # Banner echo -e "${PURPLE}${BOLD}" echo "โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—" echo "โ•‘ ๐ŸŽผ RPA Vision V3 - Chef d'Orchestre ๐ŸŽผ โ•‘" echo "โ•‘ 100% Vision-Based RPA System โ•‘" echo "โ•‘ Fiche #1 & #2 Corrections Applied โœ… โ•‘" echo "โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•" echo -e "${NC}" # Help show_help() { echo -e "${BOLD}๐ŸŽผ RPA Vision V3 - Chef d'Orchestre${NC}" echo "" echo -e "${BOLD}Usage:${NC} ./run.sh [OPTIONS]" echo "" echo -e "${BOLD}๐Ÿš€ Modes de Lancement:${NC}" echo -e " ${GREEN}--full${NC} ๐ŸŽฏ Mode COMPLET (Recommandรฉ) - Tout l'รฉcosystรจme" echo -e " ${CYAN}--gui${NC} ๐Ÿ–ฅ๏ธ Interface GUI PyQt5 (dรฉfaut)" echo -e " ${BLUE}--server${NC} ๐ŸŒ API Server seul (port 8000)" echo -e " ${PURPLE}--dashboard${NC} ๐Ÿ“Š Dashboard Web seul (port 5001)" echo -e " ${YELLOW}--monitoring${NC} ๐Ÿ“ˆ Interface de monitoring (port 5003)" echo -e " ${CYAN}--workflow${NC} ๐Ÿ”ง Visual Workflow Builder (port 3002)" echo -e " ${GREEN}--agent${NC} ๐Ÿ“น Agent V0 (capture tool)" echo -e " ${BLUE}--chat${NC} ๐Ÿ’ฌ Agent Chat (port 5004)" echo -e " ${GREEN}--stream${NC} ๐Ÿ“ก Streaming Server (port 5005)" echo "" echo -e "${BOLD}๐Ÿงช Tests & Validation:${NC}" echo -e " ${GREEN}--test${NC} ๐Ÿงช Tests complets" echo -e " ${CYAN}--test-quick${NC} โšก Tests rapides" echo -e " ${YELLOW}--test-bbox${NC} ๐Ÿ“ Tests corrections BBOX (Fiche #2)" echo -e " ${PURPLE}--demo${NC} ๐ŸŽฎ Dรฉmos d'intรฉgration" echo "" echo -e "${BOLD}๐Ÿ”ง Maintenance:${NC}" echo -e " ${YELLOW}--check${NC} โœ… Vรฉrification environnement seul" echo -e " ${RED}--reinstall${NC} ๐Ÿ”„ Rรฉinstallation forcรฉe des dรฉpendances" echo -e " ${BLUE}--status${NC} ๐Ÿ“Š Status des services" echo -e " ${GREEN}--stop${NC} ๐Ÿ›‘ Arrรชter tous les services" echo "" echo -e "${BOLD}๐Ÿ“– Exemples:${NC}" echo -e " ${GREEN}./run.sh --full${NC} # ๐ŸŽฏ ร‰cosystรจme complet (recommandรฉ)" echo -e " ${CYAN}./run.sh${NC} # ๐Ÿ–ฅ๏ธ GUI seule" echo -e " ${BLUE}./run.sh --server --dashboard${NC} # ๐ŸŒ API + Dashboard" echo -e " ${YELLOW}./run.sh --test-bbox${NC} # ๐Ÿ“ Tester corrections BBOX" echo -e " ${PURPLE}./run.sh --demo${NC} # ๐ŸŽฎ Dรฉmos d'intรฉgration" echo "" echo -e "${BOLD}๐ŸŒ URLs d'accรจs:${NC}" echo -e " API Server: ${BLUE}http://localhost:8000${NC}" echo -e " Dashboard: ${PURPLE}http://localhost:5001${NC}" echo -e " Agent Chat: ${BLUE}http://localhost:5004${NC}" echo -e " Streaming API: ${GREEN}http://localhost:5005${NC}" echo -e " Monitoring: ${YELLOW}http://localhost:5003${NC}" echo -e " Workflow Builder: ${CYAN}http://localhost:3002${NC}" echo "" } # Parse arguments MODE="gui" FORCE_REINSTALL=false CHECK_ONLY=false LAUNCH_SERVER=false LAUNCH_DASHBOARD=false LAUNCH_MONITORING=false LAUNCH_WORKFLOW=false LAUNCH_AGENT=false LAUNCH_COMMAND=false LAUNCH_STREAM=false for arg in "$@"; do case $arg in --full) MODE="full" LAUNCH_SERVER=true LAUNCH_DASHBOARD=true LAUNCH_MONITORING=true LAUNCH_WORKFLOW=true ;; --gui) MODE="gui" ;; --server|--api) MODE="server" LAUNCH_SERVER=true ;; --dashboard|--web) MODE="dashboard" LAUNCH_DASHBOARD=true ;; --monitoring|--monitor) MODE="monitoring" LAUNCH_MONITORING=true ;; --workflow|--visual) MODE="workflow" LAUNCH_WORKFLOW=true ;; --all) MODE="all" LAUNCH_SERVER=true LAUNCH_DASHBOARD=true ;; --agent) MODE="agent" LAUNCH_AGENT=true ;; --chat|--cmd) MODE="chat" LAUNCH_COMMAND=true ;; --stream) MODE="stream" LAUNCH_STREAM=true ;; --test) MODE="test" ;; --test-quick) MODE="test-quick" ;; --test-bbox) MODE="test-bbox" ;; --demo) MODE="demo" ;; --status) MODE="status" ;; --stop) MODE="stop" ;; --reinstall) FORCE_REINSTALL=true ;; --check) CHECK_ONLY=true ;; -h|--help) show_help exit 0 ;; esac done # Get script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Step 1: Check OS echo -e "${BLUE}[1/7]${NC} Checking Operating System..." OS=$(uname -s) case "$OS" in Linux*) OS_NAME="Linux";; Darwin*) OS_NAME="macOS";; MINGW*|MSYS*|CYGWIN*) OS_NAME="Windows";; *) OS_NAME="Unknown";; esac echo -e "${GREEN}โœ“${NC} OS: $OS_NAME ($(uname -m))" # Step 2: Check Python echo -e "${BLUE}[2/7]${NC} Checking Python..." if command -v python3 &> /dev/null; then PYTHON_VERSION=$(python3 --version | cut -d' ' -f2) PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d'.' -f1) PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d'.' -f2) if [ "$PYTHON_MAJOR" -ge 3 ] && [ "$PYTHON_MINOR" -ge 8 ]; then echo -e "${GREEN}โœ“${NC} Python $PYTHON_VERSION" else echo -e "${RED}โœ—${NC} Python 3.8+ required (found $PYTHON_VERSION)" exit 1 fi else echo -e "${RED}โœ—${NC} Python 3 not found" exit 1 fi # Step 3: Check/Create Virtual Environment echo -e "${BLUE}[3/7]${NC} Setting up Python environment..." VENV_DIR=".venv" if [ ! -d "$VENV_DIR" ]; then echo " Creating virtual environment..." python3 -m venv $VENV_DIR echo -e "${GREEN}โœ“${NC} Virtual environment created" else echo -e "${GREEN}โœ“${NC} Virtual environment exists" fi # Activate venv source $VENV_DIR/bin/activate # --------------------------------------------------------------------- # Fiche #23 - Sรฉcuritรฉ (anti-oubli) # - Crรฉe/charge .env.local si absent # - Fournit un lien dashboard avec token # --------------------------------------------------------------------- if [ -f "$SCRIPT_DIR/server/bootstrap_local_env.sh" ]; then chmod +x "$SCRIPT_DIR/server/bootstrap_local_env.sh" 2>/dev/null || true # shellcheck disable=SC1090 "$SCRIPT_DIR/server/bootstrap_local_env.sh" || true fi # Charge les variables dans ce script (sinon elles restent dans le sous-process) if [ -f "$SCRIPT_DIR/.env.local" ]; then set -a # shellcheck disable=SC1090 source "$SCRIPT_DIR/.env.local" set +a fi # Step 4: Install Dependencies echo -e "${BLUE}[4/7]${NC} Checking dependencies..." if [ "$FORCE_REINSTALL" = true ]; then rm -f .deps_installed fi if [ ! -f ".deps_installed" ]; then echo " Installing dependencies (this may take a few minutes)..." $VENV_DIR/bin/python3 -m pip install --upgrade pip -q $VENV_DIR/bin/python3 -m pip install -r requirements.txt -q # Server dependencies if [ -f "server/requirements_server.txt" ]; then $VENV_DIR/bin/python3 -m pip install -r server/requirements_server.txt -q fi # Dashboard dependencies if [ -f "web_dashboard/requirements.txt" ]; then $VENV_DIR/bin/python3 -m pip install -r web_dashboard/requirements.txt -q fi touch .deps_installed echo -e "${GREEN}โœ“${NC} Dependencies installed" else echo -e "${GREEN}โœ“${NC} Dependencies OK (use --reinstall to force)" fi # Step 5: Check GPU echo -e "${BLUE}[5/7]${NC} Checking GPU..." GPU_AVAILABLE=false if command -v nvidia-smi &> /dev/null; then GPU_INFO=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1) if [ ! -z "$GPU_INFO" ]; then echo -e "${GREEN}โœ“${NC} GPU: $GPU_INFO" GPU_AVAILABLE=true fi fi if [ "$GPU_AVAILABLE" = false ]; then echo -e "${YELLOW}โš ${NC} No NVIDIA GPU (using CPU)" fi # Step 6: Check Ollama echo -e "${BLUE}[6/7]${NC} Checking Ollama..." if command -v ollama &> /dev/null; then echo -e "${GREEN}โœ“${NC} Ollama installed" if ollama list 2>/dev/null | grep -q "qwen3-vl"; then echo -e "${GREEN}โœ“${NC} qwen3-vl model available" else echo -e "${YELLOW}โš ${NC} qwen3-vl not found (run: ollama pull qwen3-vl:8b)" fi else echo -e "${YELLOW}โš ${NC} Ollama not installed (optional)" fi # Step 7: Create directories echo -e "${BLUE}[7/7]${NC} Creating directories..." mkdir -p data/training/uploads mkdir -p data/training/sessions mkdir -p data/workflows mkdir -p logs mkdir -p models echo -e "${GREEN}โœ“${NC} Directories ready" # Summary echo "" echo -e "${BLUE}โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•${NC}" echo -e "${GREEN}โœ“ Environment Ready${NC}" echo -e "${BLUE}โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•${NC}" if [ "$CHECK_ONLY" = true ]; then echo "" echo "Environment check complete. Use ./run.sh --help for options." deactivate 2>/dev/null || true exit 0 fi # PIDs for cleanup API_PID="" DASHBOARD_PID="" MONITORING_PID="" WORKFLOW_PID="" COMMAND_PID="" # Service management functions start_service() { local name=$1 local command=$2 local port=$3 local log_file=$4 echo "Starting $name (port $port)..." eval "$command > logs/$log_file 2>&1 &" local pid=$! sleep 3 if kill -0 $pid 2>/dev/null; then echo -e "${GREEN}โœ“${NC} $name started (PID: $pid)" echo $pid # Retourner le PID via stdout else echo -e "${RED}โœ—${NC} $name failed to start" cat logs/$log_file echo 0 # Retourner 0 en cas d'รฉchec fi } check_service_status() { local name=$1 local port=$2 if curl -s "http://localhost:$port" > /dev/null 2>&1; then echo -e "${GREEN}โœ“${NC} $name (port $port) - Running" else echo -e "${RED}โœ—${NC} $name (port $port) - Stopped" fi } cleanup() { echo "" echo -e "${YELLOW}๐Ÿ›‘ Stopping services...${NC}" [ ! -z "$API_PID" ] && kill $API_PID 2>/dev/null || true [ ! -z "$DASHBOARD_PID" ] && kill $DASHBOARD_PID 2>/dev/null || true [ ! -z "$MONITORING_PID" ] && kill $MONITORING_PID 2>/dev/null || true [ ! -z "$WORKFLOW_PID" ] && kill $WORKFLOW_PID 2>/dev/null || true [ ! -z "$COMMAND_PID" ] && kill $COMMAND_PID 2>/dev/null || true # Kill any remaining processes on our ports (fuser est fiable, pkill -f "port" ne matche pas) for p in 8000 5001 5002 5003 5004 5005 3002; do fuser -k "${p}/tcp" 2>/dev/null || true done deactivate 2>/dev/null || true echo -e "${GREEN}โœ“${NC} Cleanup complete" exit 0 } trap cleanup SIGINT SIGTERM # Launch based on mode case $MODE in gui) echo "" echo -e "${CYAN}๐Ÿ–ฅ๏ธ Launching GUI...${NC}" $VENV_DIR/bin/python3 run_gui.py ;; server) echo "" echo -e "${BLUE}๐ŸŒ Launching API Server on port 8000...${NC}" echo "" echo "Endpoints:" echo " POST http://localhost:8000/api/traces/upload" echo " GET http://localhost:8000/api/traces/status" echo " GET http://localhost:8000/api/traces/sessions" echo " GET http://localhost:8000/api/traces/queue" echo "" $VENV_DIR/bin/python3 server/api_upload.py ;; dashboard) echo "" echo -e "${PURPLE}๐Ÿ“Š Launching Dashboard on port 5001...${NC}" echo "" echo "Access: http://localhost:5001" echo "" $VENV_DIR/bin/python3 web_dashboard/app.py ;; monitoring) echo "" echo -e "${YELLOW}๐Ÿ“ˆ Launching Monitoring Interface on port 5003...${NC}" echo "" echo "Access: http://localhost:5003" echo "" $VENV_DIR/bin/python3 monitoring_server.py ;; workflow) echo "" echo -e "${CYAN}๐Ÿ”ง Launching Visual Workflow Builder v4...${NC}" echo "" echo "Access: http://localhost:3002 (frontend) / http://localhost:5002 (backend)" echo "" cd visual_workflow_builder ./run_v4.sh cd .. ;; agent) echo "" echo -e "${GREEN}๐Ÿ“น Launching Agent V0 (capture tool)...${NC}" echo "" echo "The agent will appear in your system tray." echo "Click the icon to start/stop recording." echo "" # Export necessary environment variables for the agent export RPA_TOKEN_ADMIN="${RPA_TOKEN_ADMIN:-}" export RPA_TOKEN_READONLY="${RPA_TOKEN_READONLY:-}" export ENCRYPTION_PASSWORD="${ENCRYPTION_PASSWORD:-}" cd agent_v0 ../$VENV_DIR/bin/python3 main.py cd .. ;; chat) echo "" echo -e "${BLUE}๐Ÿ’ฌ Launching Agent Chat on port 5004...${NC}" echo "" echo "Access: http://localhost:5004" echo "" $VENV_DIR/bin/python3 agent_chat/app.py ;; stream) echo "" echo -e "${GREEN}๐Ÿ“ก Launching Streaming Server on port 5005...${NC}" echo "" echo "Access: http://localhost:5005" echo "" $VENV_DIR/bin/python3 -m agent_v0.server_v1.api_stream ;; full) echo "" echo -e "${GREEN}${BOLD}๐ŸŽฏ Launching FULL ECOSYSTEM...${NC}" echo "" # Start API server API_PID=$(start_service "API Server" "$VENV_DIR/bin/python3 server/api_upload.py" "8000" "api.log") # Start Dashboard DASHBOARD_PID=$(start_service "Dashboard" "$VENV_DIR/bin/python3 web_dashboard/app.py" "5001" "dashboard.log") # Start Monitoring MONITORING_PID=$(start_service "Monitoring" "$VENV_DIR/bin/python3 monitoring_server.py" "5003" "monitoring.log") # Start Visual Workflow Builder v4 (in background) echo "Starting Visual Workflow Builder v4 (port 3002)..." cd visual_workflow_builder ./run_v4.sh > ../logs/workflow.log 2>&1 & WORKFLOW_PID=$! cd .. sleep 3 if kill -0 $WORKFLOW_PID 2>/dev/null; then echo -e "${GREEN}โœ“${NC} Visual Workflow Builder started (PID: $WORKFLOW_PID)" else echo -e "${YELLOW}โš ${NC} Visual Workflow Builder may need manual start" fi echo "" echo -e "${GREEN}${BOLD}๐ŸŽ‰ FULL ECOSYSTEM RUNNING!${NC}" echo "" echo -e "${BOLD}๐ŸŒ Access URLs:${NC}" echo -e " API Server: ${BLUE}http://localhost:8000${NC}" echo -e " Dashboard: ${PURPLE}http://localhost:5001${NC}" echo -e " Monitoring: ${YELLOW}http://localhost:5003${NC}" echo -e " Workflow Builder: ${CYAN}http://localhost:3002${NC}" echo "" echo -e "${BOLD}๐Ÿ“Š Logs:${NC}" echo " tail -f logs/api.log" echo " tail -f logs/dashboard.log" echo " tail -f logs/monitoring.log" echo " tail -f logs/workflow.log" echo "" echo -e "${BOLD}๐ŸŽฏ Ready to test Fiche #1 & #2 corrections!${NC}" echo "" # Start GUI as main interface echo "Starting GUI as main interface..." $VENV_DIR/bin/python3 run_gui.py cleanup ;; all) echo "" echo -e "${CYAN}๐ŸŒ Launching API + Dashboard...${NC}" echo "" # Start API server API_PID=$(start_service "API Server" "$VENV_DIR/bin/python3 server/api_upload.py" "8000" "api.log") # Start Dashboard DASHBOARD_PID=$(start_service "Dashboard" "$VENV_DIR/bin/python3 web_dashboard/app.py" "5001" "dashboard.log") echo "" echo -e "${GREEN}Services running!${NC}" echo "" echo "URLs:" echo " API: http://localhost:8000" echo " Dashboard: http://localhost:5001" echo "" echo "Logs:" echo " tail -f logs/api.log" echo " tail -f logs/dashboard.log" echo "" # Start GUI echo "Starting GUI..." $VENV_DIR/bin/python3 run_gui.py cleanup ;; test) echo "" echo -e "${GREEN}๐Ÿงช Running complete tests...${NC}" echo "" $VENV_DIR/bin/python3 -m pytest tests/ -v --tb=short ;; test-quick) echo "" echo -e "${CYAN}โšก Running quick tests...${NC}" echo "" $VENV_DIR/bin/python3 -m pytest tests/ -m "not slow" -q --tb=short ;; test-bbox) echo "" echo -e "${YELLOW}๐Ÿ“ Testing BBOX corrections (Fiche #2)...${NC}" echo "" $VENV_DIR/bin/python3 -m pytest tests/unit/test_fiche2_bbox_xywh_corrections.py tests/unit/test_bbox_center_xywh.py -v ;; demo) echo "" echo -e "${PURPLE}๐ŸŽฎ Running integration demos...${NC}" echo "" echo "Available demos:" echo "1. Full Integration Demo" echo "2. Automation Demo" echo "3. Self-Healing Demo" echo "" read -p "Choose demo (1-3): " demo_choice case $demo_choice in 1) $VENV_DIR/bin/python3 demo_full_integration.py ;; 2) $VENV_DIR/bin/python3 demo_automation.py ;; 3) $VENV_DIR/bin/python3 demo_self_healing.py ;; *) echo "Invalid choice" ;; esac ;; status) echo "" echo -e "${BLUE}๐Ÿ“Š Services Status:${NC}" echo "" check_service_status "API Server" "8000" check_service_status "Dashboard" "5001" check_service_status "Agent Chat" "5004" check_service_status "Streaming API" "5005" check_service_status "Monitoring" "5003" check_service_status "Workflow Builder" "3002" echo "" ;; stop) echo "" echo -e "${RED}๐Ÿ›‘ Stopping all services...${NC}" for p in 8000 5001 5002 5003 5004 5005 3002; do fuser -k "${p}/tcp" 2>/dev/null || true done echo -e "${GREEN}โœ“${NC} All services stopped" ;; esac deactivate 2>/dev/null || true