# Dockerfile for Hugging Face Space with Diffusers-based image generation FROM python:3.10-slim # Environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ DEBIAN_FRONTEND=noninteractive \ PYTHONIOENCODING=utf-8 \ # Set Hugging Face cache directory HF_HOME=/app/.cache \ HF_HUB_CACHE=/app/.cache \ TRANSFORMERS_CACHE=/app/.cache \ # Set Git identity via environment variables to avoid permission issues GIT_AUTHOR_NAME="Defter77" \ GIT_AUTHOR_EMAIL="Defter77@users.noreply.huggingface.co" \ GIT_COMMITTER_NAME="Defter77" \ GIT_COMMITTER_EMAIL="Defter77@users.noreply.huggingface.co" # System dependencies without git (we'll install our own wrapper) RUN apt-get update && apt-get install -y \ wget \ curl \ libglib2.0-0 \ libsm6 \ libxrender1 \ libxext6 \ ffmpeg \ && rm -rf /var/lib/apt/lists/* # Create a git wrapper script that ignores git config commands RUN echo '#!/bin/sh' > /usr/local/bin/git && \ echo 'if [ "$1" = "config" ] && [ "$2" = "--global" ]; then' >> /usr/local/bin/git && \ echo ' echo "Git config bypassed"' >> /usr/local/bin/git && \ echo 'else' >> /usr/local/bin/git && \ echo ' /usr/bin/git "$@"' >> /usr/local/bin/git && \ echo 'fi' >> /usr/local/bin/git && \ chmod +x /usr/local/bin/git # Actually install real git (our wrapper will intercept config commands) RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* # Create app directory WORKDIR /app # Create cache and data directories with proper permissions RUN mkdir -p /app/.cache /app/input /app/output && \ chmod -R 777 /app/.cache /app/input /app/output # Copy requirements COPY requirements.txt ./ # Install Python dependencies RUN pip install --upgrade pip && \ pip install -r requirements.txt # Add model download script COPY download_models.py ./ RUN python download_models.py || echo "Warning: Model download may have had issues, but continuing build" # Copy application code COPY app.py ./ COPY inference.py ./ # Expose API port EXPOSE 7860 # Optional health check HEALTHCHECK --interval=30s --timeout=10s CMD curl --fail http://localhost:7860/docs || exit 1 # Run FastAPI app CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]