Spaces:
Sleeping
Sleeping
| FROM python:3.11-slim | |
| WORKDIR /app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Upgrade pip first | |
| RUN pip install --no-cache-dir --upgrade pip | |
| # Install specific versions to match your trained models | |
| RUN pip install --no-cache-dir \ | |
| numpy==1.26.4 \ | |
| scikit-learn==1.7.0 \ | |
| joblib==1.4.0 | |
| # Copy and install remaining dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application code and model files | |
| COPY . . | |
| # Debug: List all files and check model files | |
| RUN echo "=== Directory contents ===" && ls -la | |
| RUN echo "=== Looking for model files ===" && find . -name "*.pkl" -o -name "*.joblib" || echo "No model files found" | |
| # Set proper permissions | |
| RUN chmod 644 *.pkl 2>/dev/null || echo "No .pkl files found to set permissions" | |
| # Create a non-root user for security | |
| RUN useradd -m -u 1000 user | |
| RUN chown -R user:user /app | |
| USER user | |
| # Environment variables | |
| ENV PORT=7860 | |
| ENV MODEL_PATH=./isoforest_dos.pkl | |
| ENV SCALER_PATH=./scaler_dos.pkl | |
| ENV ENCODER_PATH=./encoder_dos.pkl | |
| EXPOSE $PORT | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
| CMD curl -f http://localhost:$PORT/health || exit 1 | |
| CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port $PORT"] |