File size: 1,939 Bytes
799b97a
b1d1ff4
 
 
 
 
799b97a
35e8281
 
799b97a
b1d1ff4
799b97a
b1d1ff4
 
 
 
 
 
35e8281
 
 
 
b1d1ff4
 
 
 
 
 
 
 
37b9169
b1d1ff4
799b97a
b1d1ff4
37b9169
b1d1ff4
 
 
 
35e8281
 
 
 
 
 
 
 
 
 
 
b1d1ff4
35e8281
 
b1d1ff4
 
 
 
 
 
 
 
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
FROM python:3.12-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    HF_HOME=/home/user/.cache/huggingface \
    VISUALIZER_CONFIG=visualizer.gpu.toml \
    PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
    QA_FRONTEND_DIR=/app/frontend/viz2d-demo \
    HOME=/home/user

# Install system dependencies (git for compphoto/Intrinsic installation, ffmpeg, glib for OpenCV)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        git \
        ffmpeg \
        libglib2.0-0 \
        libgomp1 \
        build-essential \
        ca-certificates \
        nodejs \
        npm && \
    rm -rf /var/lib/apt/lists/*

# Set up a new user named "user" with UID 1000 for Hugging Face permissions
RUN useradd -m -u 1000 user

WORKDIR /app

# Copy requirements files first
COPY requirements-base.txt requirements-gpu-cu126.txt ./

# Install CUDA PyTorch, MoGe, and the visualizer dependencies for GPU Spaces
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements-gpu-cu126.txt

# Copy the rest of the application files
COPY --chown=user:1000 . .

# Install optional Playwright QA runner dependencies when frontend/viz2d-demo
# is included in the Hugging Face Space.
RUN if [ -f frontend/viz2d-demo/package-lock.json ]; then \
        cd frontend/viz2d-demo && \
        npm ci && \
        npx playwright install --with-deps chromium; \
    else \
        echo "frontend/viz2d-demo not found; skipping Playwright QA runner install"; \
    fi && \
    rm -rf /var/lib/apt/lists/*

# Create writable data directories and change ownership
RUN mkdir -p data/uploads data/jobs data/qa-runs /ms-playwright && \
    chown -R user:1000 /app /ms-playwright

# Switch to the non-root user
USER user

# Hugging Face Spaces expects the application on port 7860
EXPOSE 7860

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]