saap-plattform / start_backend.sh
Hwandji's picture
feat: initial HuggingFace Space deployment
4343907
#!/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