# Use an official Python runtime as the base image FROM python:3.11-slim # Set working directory inside the container WORKDIR /app # Create a non-root user to match Hugging Face Spaces' setup # UID 1000 is commonly used in Spaces, but this may vary RUN useradd -m -u 1000 appuser # Create the saved_models directory and set ownership to appuser RUN mkdir -p /app/saved_models && chown -R appuser:appuser /app # Copy requirements.txt to the working directory COPY requirements.txt . # Install system dependencies (for faiss, torch, etc.) RUN apt-get update && apt-get install -y \ build-essential \ libatlas-base-dev \ gfortran \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the entire application code and datasets to the container COPY . . # Set ownership of all files to appuser RUN chown -R appuser:appuser /app # Switch to the non-root user USER appuser # Expose the port your Flask app will run on (7860 as specified in app.py) EXPOSE 7860 # Command to run the Flask app CMD ["python", "app.py"]