# Use a slim Python base image FROM python:3.11-slim # Set environment variables to prevent bytecode generation and buffer output ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # Set Hugging Face cache directory ENV HF_HOME=/app/hf_cache # Install system dependencies required for OpenCV and other libraries RUN apt-get update && apt-get install -y --no-install-recommends \ git \ ffmpeg \ libgl1-mesa-glx \ libglib2.0-0 \ build-essential \ curl \ wget \ && rm -rf /var/lib/apt/lists/* # Set the working directory WORKDIR /app # Copy the requirements file COPY requirements.txt . # Install Python dependencies, ensuring we get the CPU-only version of PyTorch # This significantly reduces the Docker image size and is crucial for CPU-only environments RUN pip install --upgrade pip RUN pip install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu # Copy the rest of the application code COPY . . # Pre-download the model weights during the build process # This prevents downloading the model every time the container starts, leading to faster startup RUN python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='eugenesiow/real-esrgan', filename='RealESRGAN_x4plus.pth', cache_dir=None, local_dir='./weights')" # Expose the port the app will run on EXPOSE 8000 # Command to run the application using uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]