File size: 3,277 Bytes
900c7c1
 
 
 
 
 
a80542f
900c7c1
a80542f
 
900c7c1
 
 
 
 
 
 
 
 
 
 
0626a6b
 
 
 
 
 
 
900c7c1
 
0626a6b
 
900c7c1
 
 
 
 
 
 
40dd166
 
 
 
1a24d4a
3909559
 
 
 
 
 
a80542f
 
900c7c1
545c818
 
 
 
 
 
 
 
 
 
 
900c7c1
 
 
 
 
 
 
3e18d9a
900c7c1
 
 
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
# syntax=docker/dockerfile:1.7
#
# Hugging Face Space (sdk: docker) for the CADGenBench leaderboard.
#
# HF builds this server-side on each git push. Local smoke test:
#
#     docker buildx build --platform linux/amd64 -t cadgenbench-space-test .
#
# cadgenbench is installed from github.com/huggingface/cadgenbench, which
# is Public. No build secrets or auth required.

FROM python:3.12-slim-bookworm

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    GRADIO_SERVER_NAME=0.0.0.0 \
    GRADIO_SERVER_PORT=7860

# OS deps:
#   git, ca-certificates           -> pip install from git+https://
#   libglib2.0-0, libsm6, libxext6,
#   libgomp1, libfontconfig1       -> OCP / build123d / Pillow runtime
#   libgl1, libglx-mesa0, libegl1,
#   libegl-mesa0, libxrender1      -> VTK / PyVista off-screen GL context.
# The HF Space's cpu-upgrade tier has no GPU; VTK's EGL backend picks up
# Mesa's software rasteriser (libegl-mesa0) at runtime, no code change.
# A GPU host gets hardware OpenGL via the same libs.
RUN apt-get update && apt-get install -y --no-install-recommends \
        git ca-certificates \
        libglib2.0-0 libsm6 libxext6 libgomp1 libfontconfig1 \
        libgl1 libglx-mesa0 libegl1 libegl-mesa0 libxrender1 \
    && rm -rf /var/lib/apt/lists/*

# Space-side Python deps (gradio, pandas, huggingface_hub, datasets).
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt \
    && rm /tmp/requirements.txt

# cadgenbench from the Public GitHub repo. Defaults to `main` so every
# image rebuild picks up the latest code (pre-v1: always-updated). Lock
# to a specific commit SHA at the v1 release so published scores are
# reproducible (see space-setup/post-gt-swap.md Stage F).
ARG CADGENBENCH_SHA=1010043
# Cache-bust the install below whenever the tracked ref moves: the
# GitHub commits endpoint's response changes with each new commit on
# `main`, so BuildKit re-fetches and invalidates the cached pip layer.
# Without it, `@main` would stay pinned to whatever `main` was at first
# build. Stable (a no-op) when CADGENBENCH_SHA is a fixed commit SHA.
ADD https://api.github.com/repos/huggingface/cadgenbench/commits/${CADGENBENCH_SHA} /tmp/cadgenbench.commit
RUN pip install --no-cache-dir \
        "cadgenbench @ git+https://github.com/huggingface/cadgenbench.git@${CADGENBENCH_SHA}"

# The stock `vtk` wheel that pyvista pulls from PyPI is built with
# vtkXOpenGLRenderWindow, which needs an X server and segfaults the
# worker on a truly-headless container (no DISPLAY). Swap it for
# `vtk-osmesa`, the same VTK build but compiled against OSMesa (pure
# CPU software rasteriser, self-contained, no display server required).
# This is the canonical PyVista headless-Docker recipe; the wheel
# comes from Kitware's index, not PyPI proper.
RUN pip uninstall -y vtk \
    && pip install --no-cache-dir \
        --extra-index-url https://wheels.vtk.org vtk-osmesa

# Drop privileges. HF Spaces conventionally run as uid 1000 with
# WORKDIR /home/user/app.
RUN useradd -m -u 1000 user \
    && mkdir -p /home/user/app \
    && chown -R user:user /home/user/app
USER user
WORKDIR /home/user/app
COPY --chown=user:user *.py ./

EXPOSE 7860
CMD ["python", "app.py"]