# Use Python 3.10 slim as the base image for compatibility with FastSD CPU FROM python:3.10-slim # Set working directory WORKDIR /app # Install system dependencies required for FastSD CPU RUN apt-get update && apt-get install -y \ git \ libgl1 \ libglib2.0-0 \ wget \ && rm -rf /var/lib/apt/lists/* # Clone the FastSD CPU repository RUN git clone https://github.com/rupeshs/fastsdcpu.git . # Create a virtual environment and activate it RUN python -m venv /app/env ENV PATH="/app/env/bin:$PATH" # Upgrade pip and install Python dependencies RUN pip install --no-cache-dir --upgrade pip RUN pip install --no-cache-dir -r requirements.txt # Install OpenVINO for performance optimization (optional) RUN pip install --no-cache-dir openvino-dev # Pre-download the default model (stabilityai/sd-turbo) to avoid runtime downloads RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='stabilityai/sd-turbo', local_dir='/app/models/sd-turbo')" # Expose port 8000 for the API server EXPOSE 8000 # Set environment variables for Hugging Face Spaces ENV PYTHONUNBUFFERED=1 ENV DEVICE=cpu # Command to run the API server CMD ["python", "src/app.py", "--api"]