# Use the official Python 3.9 slim image FROM python:3.9-slim # Create a user with UID 1000 (Required for Hugging Face Spaces security) RUN useradd -m -u 1000 user USER user # Add local bin to PATH to ensure pip installed packages are found ENV PATH="/home/user/.local/bin:$PATH" # Set the working directory WORKDIR /app # Copy the requirements file first to leverage Docker cache COPY --chown=user ./requirements.txt requirements.txt # Step 1: Install PyTorch CPU version specifically (to save space and fix compatibility) # We use torch 2.4.0 to resolve conflicts with newer transformers libraries RUN pip install --no-cache-dir torch==2.4.0 --index-url https://download.pytorch.org/whl/cpu # Step 2: Install the rest of the dependencies from requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code COPY --chown=user . /app # Expose the port used by Hugging Face Spaces EXPOSE 7860 # Command to start the application using Uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]