| # Use the official lightweight Python image. | |
| # https://hub.docker.com/_/python | |
| FROM python:3.9-slim | |
| # Set the working directory to /app | |
| WORKDIR /app | |
| # Copy the requirements file into the container at /app | |
| COPY requirements.txt . | |
| # Install any needed packages specified in requirements.txt | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the rest of the application code | |
| COPY . . | |
| # Create the SQLite database directory permissions if needed (HF spaces are writable in /app) | |
| # But standard SQLite file in CWD is fine. | |
| # Make sure the model is generated during build or on startup | |
| # We run the training script during build to ensure model.pkl exists | |
| RUN python -c "import model; model.train_model()" | |
| # Expose port 7860 (Hugging Face Spaces default port) | |
| EXPOSE 7860 | |
| # Run commands to start the server | |
| # binding to 0.0.0.0 is crucial for Docker containers | |
| CMD ["python", "app.py"] | |