File size: 6,789 Bytes
712579e |
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 |
#!/bin/bash
# run.sh - Main execution script for Wisal Autism AI Assistant
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[*]${NC} $1"
}
print_success() {
echo -e "${GREEN}[+]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
print_error() {
echo -e "${RED}[-]${NC} $1"
}
# Function to check if conda is available
check_conda() {
if command -v conda &> /dev/null; then
return 0
else
return 1
fi
}
# Function to check if a conda environment exists
conda_env_exists() {
local env_name=$1
conda info --envs | grep -q "^$env_name "
}
# Function to validate environment variables
validate_env() {
local missing_vars=()
# Check required environment variables
[[ -z "$GEMINI_API_KEY" ]] && missing_vars+=("GEMINI_API_KEY")
[[ -z "$SILICONFLOW_API_KEY" ]] && missing_vars+=("SILICONFLOW_API_KEY")
[[ -z "$SILICONFLOW_CHAT_URL" ]] && missing_vars+=("SILICONFLOW_CHAT_URL")
if [ ${#missing_vars[@]} -ne 0 ]; then
print_error "Missing required environment variables:"
for var in "${missing_vars[@]}"; do
echo " - $var"
done
echo ""
echo "Please ensure these variables are set in your .env file."
return 1
fi
print_success "All required environment variables are present."
return 0
}
# Function to check if .env file exists and load it
check_env_file() {
if [ -f ".env" ]; then
print_status "Loading environment variables from .env file..."
export $(grep -v '^#' .env | xargs)
return 0
else
print_warning ".env file not found in current directory."
echo "Please create a .env file with your API keys."
echo "See .env.example for reference."
return 1
fi
}
# Function to install requirements with pip
install_requirements() {
print_status "Installing Python requirements..."
if pip install -r requirements.txt; then
print_success "Requirements installed successfully."
return 0
else
print_error "Failed to install requirements."
return 1
fi
}
# Function to create a new conda environment
create_conda_env() {
local env_name="wisal-env"
local python_version="3.10"
print_status "Creating new conda environment: $env_name with Python $python_version..."
if conda create -n "$env_name" python=$python_version -y; then
print_success "Conda environment '$env_name' created successfully."
# Activate the environment
eval "$(conda shell.bash hook)"
conda activate "$env_name"
# Install requirements
if install_requirements; then
return 0
else
print_error "Failed to install requirements in conda environment."
return 1
fi
else
print_error "Failed to create conda environment."
return 1
fi
}
# Function to use existing conda environment
use_existing_conda_env() {
local env_name=$1
print_status "Activating existing conda environment: $env_name..."
# Initialize conda for bash shell
eval "$(conda shell.bash hook)"
if conda activate "$env_name"; then
print_success "Conda environment '$env_name' activated."
# Install/upgrade requirements
print_status "Installing/updating Python requirements..."
if install_requirements; then
return 0
else
print_error "Failed to install requirements."
return 1
fi
else
print_error "Failed to activate conda environment '$env_name'."
return 1
fi
}
# Function to run the application
run_application() {
print_status "Starting Wisal Autism AI Assistant..."
# Validate environment variables
if ! validate_env; then
print_error "Environment validation failed. Cannot start application."
exit 1
fi
# Run the main application
print_success "Launching Wisal application..."
echo ""
python main.py
}
# Main script execution
main() {
echo "==============================================="
echo " 🚀 Wisal Autism AI Assistant - Launcher"
echo "==============================================="
echo ""
# Check if .env file exists
if ! check_env_file; then
read -p "Do you want to continue without .env file? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_error "Exiting. Please create a .env file with your API keys."
exit 1
fi
fi
echo ""
echo "Please select an option to run Wisal:"
echo " 1) Use existing conda environment"
echo " 2) Create new conda environment"
echo " 3) Install requirements with current Python environment"
echo ""
read -p "Enter your choice (1-3): " choice
case $choice in
1)
if ! check_conda; then
print_error "Conda is not installed or not in PATH."
exit 1
fi
echo ""
echo "Available conda environments:"
conda info --envs | grep -v "#"
echo ""
read -p "Enter the name of the conda environment to use: " env_name
if [ -z "$env_name" ]; then
print_error "Environment name cannot be empty."
exit 1
fi
if ! conda_env_exists "$env_name"; then
print_error "Conda environment '$env_name' does not exist."
exit 1
fi
if use_existing_conda_env "$env_name"; then
run_application
else
print_error "Failed to set up conda environment."
exit 1
fi
;;
2)
if ! check_conda; then
print_error "Conda is not installed or not in PATH."
exit 1
fi
if create_conda_env; then
run_application
else
print_error "Failed to create conda environment."
exit 1
fi
;;
3)
if install_requirements; then
run_application
else
print_error "Failed to install requirements."
exit 1
fi
;;
*)
print_error "Invalid choice. Please select 1, 2, or 3."
exit 1
;;
esac
}
# Run main function
main "$@" |