FROM python:3.11-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ GENAI_PORT=7860 \ HOME=/home/user # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ git \ && rm -rf /var/lib/apt/lists/* # Create a non-root user (required by Hugging Face Spaces) RUN useradd -m -u 1000 user WORKDIR /app # Install CPU-only PyTorch first to reduce container size and build time RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu # Copy and install requirements COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application files COPY --chown=user:user . . RUN chown -R user:user /app # Switch to the non-root user USER user # Run the model download script during build so the space starts up instantly RUN python download_model.py # Expose the default Hugging Face Space port EXPOSE 7860 # Run the Flask app CMD ["python", "genai_app.py"]