HairFastGANendpoint / Dockerfile
jefrisuparjanaAI's picture
Update Dockerfile
21b8f1b verified
Raw
History Blame Contribute Delete
2.21 kB
# Optimized Dockerfile for HuggingFace Spaces
# Uses pre-built binaries and CPU-only PyTorch to reduce build time and memory
FROM python:3.10-slim
# Reduce memory usage during build
ENV MAKEFLAGS="-j1"
ENV MAX_JOBS=1
ENV PIP_NO_CACHE_DIR=1
WORKDIR /app
# Install system dependencies (minimal set)
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ffmpeg \
libsm6 \
libxext6 \
libgl1 \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
COPY requirements.txt .
# Install dependencies in optimal order (smallest to largest)
# This helps if build fails partway through
# 1. Basic tools
RUN pip install --no-cache-dir pip setuptools wheel -U
# 2. Lightweight packages
RUN pip install --no-cache-dir \
pillow==10.0.0 \
addict==2.4.0 \
cachetools==5.3.3 \
gdown==3.12.2
# 3. Flask
RUN pip install --no-cache-dir \
flask==3.0.0 \
flask-cors==4.0.0 \
werkzeug==3.0.1
# 4. gRPC
RUN pip install --no-cache-dir \
grpcio==1.63.0 \
grpcio-tools==1.63.0
# 5. Install PyTorch CPU-only (much smaller, ~100MB vs 800MB)
RUN pip install --no-cache-dir \
torch==2.1.0+cpu \
torchvision==0.16.0+cpu \
--index-url https://download.pytorch.org/whl/cpu
# 6. Install CLIP dependencies
RUN pip install --no-cache-dir ftfy regex tqdm
# 7. Install CLIP
RUN pip install --no-cache-dir git+https://github.com/openai/CLIP.git
# 8. Install face detection (use mediapipe instead of dlib to avoid compilation)
RUN pip install --no-cache-dir \
mediapipe==0.10.9 \
opencv-python-headless==4.8.1.78
# 9. Face alignment dependencies
RUN pip install --no-cache-dir \
scipy \
scikit-image \
numba
# 10. Install face_alignment (without dlib dependency)
RUN pip install --no-cache-dir face_alignment==1.3.4
# 11. Install Gradio last
RUN pip install --no-cache-dir gradio==4.31.5
# Copy all application files
COPY . .
# Create necessary directories
RUN mkdir -p /app/models /app/input /app/output
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV GRADIO_SERVER_NAME=0.0.0.0
ENV GRADIO_SERVER_PORT=7860
# Expose port for Gradio
EXPOSE 7860
# Run Gradio app (HuggingFace Spaces expects this)
CMD ["python", "app.py"]