# Use an official PyTorch image WITH CUDA development headers required for compiling FROM pytorch/pytorch:2.1.2-cuda12.1-cudnn8-devel # Prevent interactive prompts during apt-get installations ENV DEBIAN_FRONTEND=noninteractive # Tell PyTorch which GPU architectures to compile for explicitly ENV TORCH_CUDA_ARCH_LIST="7.5 8.0 8.6 8.9 9.0" # 🛑 THE FIX: Throttle the compiler to prevent Out Of Memory (OOMKilled) crashes ENV MAX_JOBS=2 # Set the working directory WORKDIR /app # Install system dependencies for C++/CUDA extensions, 3D processing, and SSH access RUN apt-get update && apt-get install -y \ git \ build-essential \ ninja-build \ libgl1 \ libglib2.0-0 \ tmate \ openssh-client \ && rm -rf /var/lib/apt/lists/* # Clone the official Hunyuan3D-2 repository RUN git clone https://github.com/Tencent/Hunyuan3D-2.git /app/Hunyuan3D-2 # Install the base Python requirements from the Tencent repository FIRST RUN pip install --no-cache-dir -r /app/Hunyuan3D-2/requirements.txt # Copy your local requirements and install them COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Explicitly force NumPy to stay below 2.0 right before compiling RUN pip install --no-cache-dir "numpy<2" # Compile the Custom Rasterizer (Required for Textures) WORKDIR /app/Hunyuan3D-2/hy3dgen/texgen/custom_rasterizer RUN python setup.py install # Compile the Differentiable Renderer (Required for Textures) WORKDIR /app/Hunyuan3D-2/hy3dgen/texgen/differentiable_renderer RUN python setup.py install # Move back to the root app directory WORKDIR /app # Copy your API script into the container COPY app.py . # Create a directory to store generated outputs temporarily RUN mkdir -p /app/outputs # Expose the default Hugging Face Spaces port EXPOSE 7860 # Command to start the FastAPI application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]