Spaces:
Sleeping
Sleeping
| # Use Python 3.10 slim image for smaller size and better compatibility | |
| FROM python:3.10-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Set environment variables for Python optimization | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV TORCH_HOME=/app/.cache/torch | |
| ENV HF_HOME=/app/.cache/huggingface | |
| # Install system dependencies required for audio processing | |
| RUN apt-get update && apt-get install -y \ | |
| # Audio processing libraries | |
| ffmpeg \ | |
| libsndfile1 \ | |
| libsndfile1-dev \ | |
| # Build tools (needed for some Python packages) | |
| build-essential \ | |
| # Cleanup to reduce image size | |
| && rm -rf /var/lib/apt/lists/* \ | |
| && apt-get clean | |
| # Upgrade pip and install Python build tools | |
| RUN pip install --no-cache-dir --upgrade pip setuptools wheel | |
| # Copy requirements file first (for better Docker layer caching) | |
| COPY requirements.txt . | |
| # Install Python dependencies with optimizations | |
| RUN pip install --no-cache-dir -r requirements.txt \ | |
| && pip cache purge | |
| # Copy application files | |
| COPY . . | |
| # Create cache directories with proper permissions | |
| RUN mkdir -p /app/.cache/torch /app/.cache/huggingface \ | |
| && chmod -R 755 /app/.cache | |
| # Create non-root user for security (optional but recommended) | |
| RUN groupadd -r appuser && useradd -r -g appuser appuser \ | |
| && chown -R appuser:appuser /app | |
| USER appuser | |
| # Health check to ensure the service is running | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| # Expose the port that HuggingFace Spaces expects | |
| EXPOSE 7860 | |
| # Command to run the FastAPI application | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] | |