Spaces:
Sleeping
Sleeping
File size: 2,865 Bytes
4343907 |
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 |
#!/bin/bash
# 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
|