File size: 2,453 Bytes
e2d5029
 
54d8ff9
 
 
 
 
 
 
e2d5029
54d8ff9
 
 
 
 
e2d5029
54d8ff9
 
 
 
 
 
 
e2d5029
704d2d3
54d8ff9
 
 
 
704d2d3
 
 
 
54d8ff9
86b6cf6
 
 
e2d5029
86b6cf6
54d8ff9
e2d5029
86b6cf6
54d8ff9
e2d5029
 
 
54d8ff9
 
e2d5029
54d8ff9
 
 
e2d5029
54d8ff9
 
 
e2d5029
54d8ff9
 
 
e2d5029
54d8ff9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e2d5029
 
54d8ff9
 
 
 
 
 
 
e2d5029
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Infinigen Agents - Modern Python-based Terrain Engine
# No legacy C++/CUDA compilation needed - uses HuggingFace Kernels + PyTorch Geometric
FROM python:3.11-slim AS builder

# Python environment setup for UV
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
ENV UV_CACHE_DIR=/tmp/.uv-cache

# System dependencies (minimal - no CUDA toolkit needed)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        curl \
        ca-certificates \
        git \
        build-essential \
        libopenblas-dev \
    && rm -rf /var/lib/apt/lists/*

# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:/usr/local/bin:/usr/bin:/bin:$PATH"

# Clone infinigen from GitHub
RUN git clone https://github.com/bjoernbethge/infinigen.git /app

# Set up working directory
WORKDIR /app

# Create virtual environment
RUN uv venv /app/.venv
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"

# Install torch first (needed for torch-scatter build)
RUN sh -c "ulimit -n 4096 && uv pip install torch --index-url https://download.pytorch.org/whl/cpu"

# Install Python dependencies (modern terrain engine uses kernels, torch_geometric, gpytorch)
RUN sh -c "ulimit -n 4096 && uv sync --no-build-isolation"

# Install Gradio and HuggingFace dependencies for Space
RUN sh -c "ulimit -n 4096 && uv pip install gradio>=5.0.0 pydantic-ai[huggingface]>=1.0.8"

# Create user
RUN useradd -ms /bin/bash user && \
    chown -R user:user /app

# ============================================
# Runtime stage - minimal image
# ============================================
FROM python:3.11-slim AS runtime

# Runtime environment
ENV UV_COMPILE_BYTECODE=1
ENV UV_CACHE_DIR=/tmp/.uv-cache

# Minimal runtime dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        libopenblas0 \
        libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# Create user (HuggingFace Spaces standard)
RUN useradd -ms /bin/bash user

# Copy built artifacts from builder stage
COPY --from=builder /app /app
COPY --from=builder /root/.local /root/.local

# Set up environment
ENV PATH="/app/.venv/bin:/root/.local/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
ENV VIRTUAL_ENV=/app/.venv
ENV HOME=/home/user

WORKDIR /app

# Copy Gradio app
COPY app.py /app/app.py

# Set ownership
RUN chown -R user:user /app

# Switch to user
USER user

# Expose Gradio port
EXPOSE 7860

# Start Gradio app
CMD ["python", "app.py"]