| # Use a Python base image suitable for slim deployments | |
| FROM python:3.9-slim | |
| # Set the working directory in the container | |
| WORKDIR /app | |
| # --- Handle caching for Sentence-Transformers and Hugging Face models --- | |
| # Create a writable directory for the Hugging Face cache | |
| # Ensure permissions allow the application user (root by default in this base image) to write | |
| RUN mkdir -p /app/.cache && chmod 777 /app/.cache | |
| # Set the environment variable to tell Hugging Face libraries where to cache models | |
| ENV HUGGINGFACE_HUB_CACHE="/app/.cache" | |
| # --- Install Dependencies --- | |
| # Copy the requirements file first to leverage Docker cache layers | |
| COPY requirements.txt . | |
| # Install the Python dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # --- Copy Application Code --- | |
| # Copy the rest of the application code into the working directory | |
| # Explicitly copy directories to ensure they land in the correct place relative to /app | |
| COPY app.py . | |
| COPY templates /app/templates | |
| COPY static /app/static | |
| # Copy the README file - Corrected: comment moved to its own line | |
| COPY README.md . | |
| # --- Configure Application Startup --- | |
| # Expose the port the Flask app will run on. Hugging Face Spaces Docker requires 7860. | |
| EXPOSE 7860 | |
| # Define the command to run your application using Waitress | |
| # Waitress serves the 'app' object from your 'app.py' file | |
| # It listens on all interfaces (0.0.0.0) on port 7860 | |
| CMD ["waitress-serve", "--listen=0.0.0.0:7860", "app:app"] |