Spaces:
Running
Running
File size: 2,755 Bytes
035a845 046ad45 035a845 046ad45 035a845 |
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 |
#!/bin/bash
# Text Summarizer API Startup Script
# This script ensures the server starts with the correct configuration
set -e # Exit on any error
echo "π Starting Text Summarizer API Server..."
# Check if .env file exists, if not create it with defaults
if [ ! -f .env ]; then
echo "π Creating .env file with default configuration..."
cat > .env << 'EOF'
# Text Summarizer API Configuration
OLLAMA_HOST=http://127.0.0.1:11434
OLLAMA_MODEL=llama3.2:latest
OLLAMA_TIMEOUT=30
SERVER_HOST=0.0.0.0
SERVER_PORT=8000
LOG_LEVEL=INFO
API_KEY_ENABLED=false
RATE_LIMIT_ENABLED=false
RATE_LIMIT_REQUESTS=60
RATE_LIMIT_WINDOW=60
MAX_TEXT_LENGTH=32000
MAX_TOKENS_DEFAULT=256
EOF
echo "β
.env file created with default values"
fi
# Check if Ollama is running
echo "π Checking Ollama service..."
if curl -s http://127.0.0.1:11434/api/tags > /dev/null 2>&1; then
echo "β
Ollama is running and accessible"
# Check if the configured model is available
MODEL=$(grep OLLAMA_MODEL .env | cut -d'=' -f2)
if curl -s http://127.0.0.1:11434/api/tags | grep -q "\"$MODEL\""; then
echo "β
Model '$MODEL' is available"
else
echo "β οΈ Warning: Model '$MODEL' not found in Ollama"
echo " Available models:"
curl -s http://127.0.0.1:11434/api/tags | grep -o '"name":"[^"]*"' | sed 's/"name":"//g' | sed 's/"//g' | sed 's/^/ - /'
fi
else
echo "β Ollama is not running or not accessible at http://127.0.0.1:11434"
echo " Please start Ollama first:"
echo " - On macOS: Open Ollama app or run 'ollama serve'"
echo " - On Linux: run 'ollama serve'"
echo " - On Windows: Open Ollama app"
exit 1
fi
# Kill any existing server on the configured port
PORT=$(grep SERVER_PORT .env | cut -d'=' -f2)
if lsof -i :$PORT > /dev/null 2>&1; then
echo "π Stopping existing server on port $PORT..."
# Try multiple methods to kill the process
pkill -f "uvicorn.*app.main:app" || true
pkill -f "uvicorn.*$PORT" || true
# Force kill any process using the port
lsof -ti :$PORT | xargs kill -9 2>/dev/null || true
sleep 3
# Verify port is free
if lsof -i :$PORT > /dev/null 2>&1; then
echo "β οΈ Warning: Could not free port $PORT, trying to continue anyway..."
else
echo "β
Port $PORT is now free"
fi
fi
# Start the server
echo "π Starting FastAPI server..."
echo " Server will be available at: http://localhost:$PORT"
echo " API docs will be available at: http://localhost:$PORT/docs"
echo " Press Ctrl+C to stop the server"
echo ""
# Load environment variables and start uvicorn
export $(cat .env | grep -v '^#' | xargs)
uvicorn app.main:app --host $SERVER_HOST --port $SERVER_PORT --reload
|