Spaces:
Sleeping
Sleeping
| # SAAP Backend Startup Script | |
| # Starts the FastAPI backend server with Uvicorn | |
| set -e # Exit on error | |
| echo "π SAAP Backend Startup" | |
| echo "=======================" | |
| # Navigate to script directory | |
| cd "$(dirname "$0")" | |
| # Check for virtual environment and activate | |
| if [ -d ".venv" ]; then | |
| echo "β Activating virtual environment (.venv)..." | |
| source .venv/bin/activate | |
| elif [ -d "venv" ]; then | |
| echo "β Activating virtual environment (venv)..." | |
| source venv/bin/activate | |
| else | |
| echo "β οΈ No virtual environment found. Creating .venv..." | |
| python3 -m venv .venv | |
| source .venv/bin/activate | |
| echo "π¦ Installing dependencies from requirements.txt..." | |
| pip install --upgrade pip | |
| pip install -r requirements.txt | |
| fi | |
| # Check if dependencies need updating (greenlet, aiosqlite for async SQLAlchemy) | |
| echo "π Checking critical dependencies..." | |
| if ! python -c "import greenlet" 2>/dev/null; then | |
| echo "π¦ Installing missing greenlet library..." | |
| pip install greenlet aiosqlite | |
| fi | |
| # Check if uvicorn is installed (verify dependencies) | |
| if ! python -c "import uvicorn" 2>/dev/null; then | |
| echo "β οΈ Dependencies not found in virtual environment" | |
| echo "π¦ Installing dependencies from requirements.txt..." | |
| pip install --upgrade pip | |
| pip install -r requirements.txt | |
| fi | |
| # Check for .env file | |
| if [ -f "backend/.env" ]; then | |
| echo "β Loading environment variables from backend/.env" | |
| set -a # Automatically export all variables | |
| source backend/.env | |
| set +a # Disable auto-export | |
| else | |
| echo "β οΈ No backend/.env file found!" | |
| if [ -f "backend/.env.example" ]; then | |
| echo "π Creating backend/.env from template..." | |
| cp backend/.env.example backend/.env | |
| echo "" | |
| echo "β οΈ IMPORTANT: Please configure backend/.env with your settings!" | |
| echo " Required: DATABASE_URL, OPENROUTER_API_KEY, COLOSSUS_API_KEY" | |
| echo "" | |
| read -p "Press Enter to continue with default values (not recommended) or Ctrl+C to exit and configure .env..." | |
| else | |
| echo "β No .env.example template found. Please create backend/.env manually." | |
| exit 1 | |
| fi | |
| fi | |
| # Navigate to backend directory | |
| cd backend | |
| # Check if main.py exists | |
| if [ ! -f "main.py" ]; then | |
| echo "β Error: backend/main.py not found!" | |
| exit 1 | |
| fi | |
| echo "" | |
| echo "π Starting SAAP Backend Server..." | |
| echo " - FastAPI + Uvicorn" | |
| echo " - Host: 0.0.0.0" | |
| echo " - Port: 8000" | |
| echo " - Auto-reload: enabled" | |
| echo "" | |
| echo "π‘ API will be available at: http://localhost:8000" | |
| echo "π API Docs (Swagger): http://localhost:8000/docs" | |
| echo "π Alternative Docs (ReDoc): http://localhost:8000/redoc" | |
| echo "" | |
| echo "Press Ctrl+C to stop the server" | |
| echo "" | |
| # Start the backend server | |
| python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000 | |