Fix: Update Dockerfile to use torch 2.0.0 and cairosvg
Browse files- Dockerfile +13 -28
Dockerfile
CHANGED
|
@@ -2,23 +2,24 @@ FROM python:3.8-slim
|
|
| 2 |
|
| 3 |
WORKDIR /code
|
| 4 |
|
| 5 |
-
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
python3-dev \
|
| 9 |
-
|
| 10 |
pkg-config \
|
| 11 |
libpng-dev \
|
| 12 |
-
libcairo2-dev \
|
| 13 |
libffi-dev \
|
| 14 |
-
cmake \
|
| 15 |
-
git \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
-
# Install
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
RUN pip install --no-cache-dir \
|
| 20 |
-
torch==1.13.1 \
|
| 21 |
-
torchvision==0.14.1 \
|
| 22 |
diffusers==0.15.1 \
|
| 23 |
transformers==4.27.4 \
|
| 24 |
accelerate==0.18.0 \
|
|
@@ -30,22 +31,6 @@ RUN pip install --no-cache-dir \
|
|
| 30 |
uvicorn==0.22.0 \
|
| 31 |
python-multipart==0.0.6
|
| 32 |
|
| 33 |
-
# Install SVG dependencies
|
| 34 |
-
RUN pip install --no-cache-dir \
|
| 35 |
-
cairosvg==2.7.0 \
|
| 36 |
-
cairocffi==1.5.1 \
|
| 37 |
-
cssselect2==0.7.0 \
|
| 38 |
-
defusedxml==0.7.1 \
|
| 39 |
-
tinycss2==1.2.1 \
|
| 40 |
-
svgwrite==1.4.3 \
|
| 41 |
-
svgpathtools==1.6.0
|
| 42 |
-
|
| 43 |
-
# Install image processing libraries
|
| 44 |
-
RUN pip install --no-cache-dir \
|
| 45 |
-
opencv-python-headless==4.7.0.72 \
|
| 46 |
-
scikit-image==0.20.0 \
|
| 47 |
-
matplotlib==3.7.1
|
| 48 |
-
|
| 49 |
# Create mock diffvg package
|
| 50 |
RUN mkdir -p /tmp/mock_diffvg/pydiffvg && \
|
| 51 |
echo '# Mock diffvg package\nimport numpy as np\nimport torch\n\ndef render(shapes, shape_groups, width, height, samples=2, seed=None):\n return torch.zeros((height, width, 3), dtype=torch.float32)\n\ndef render_shape_group(canvas, shape_group_id, shapes, shape_groups, shape_ids, samples=2, seed=None):\n pass\n\ndef save_svg(shapes, shape_groups, filename, width, height, use_gamma=False, background=None):\n with open(filename, "w") as f:\n f.write(f"<svg width=\\"{width}\\" height=\\"{height}\\" xmlns=\\"http://www.w3.org/2000/svg\\"><rect width=\\"100%\\" height=\\"100%\\" fill=\\"white\\"/></svg>")\n\ndef svg_path_to_shapes(path_string):\n return [], []\n\ndef from_svg(filename):\n return [], []\n\nclass Circle:\n def __init__(self, radius=1.0, center=None):\n self.radius = radius\n self.center = center if center is not None else torch.tensor([0.0, 0.0])\n\nclass Ellipse:\n def __init__(self, radius=None, center=None):\n self.radius = radius if radius is not None else torch.tensor([1.0, 1.0])\n self.center = center if center is not None else torch.tensor([0.0, 0.0])\n\nclass Path:\n def __init__(self, points=None, is_closed=True):\n self.points = points if points is not None else torch.tensor([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])\n self.is_closed = is_closed\n\nclass Rect:\n def __init__(self, p_min=None, p_max=None):\n self.p_min = p_min if p_min is not None else torch.tensor([0.0, 0.0])\n self.p_max = p_max if p_max is not None else torch.tensor([1.0, 1.0])\n\nclass ShapeGroup:\n def __init__(self, shape_ids=None, fill_color=None, stroke_color=None):\n self.shape_ids = shape_ids if shape_ids is not None else []\n self.fill_color = fill_color if fill_color is not None else torch.tensor([1.0, 1.0, 1.0, 1.0])\n self.stroke_color = stroke_color if stroke_color is not None else torch.tensor([0.0, 0.0, 0.0, 1.0])' > /tmp/mock_diffvg/pydiffvg/__init__.py && \
|
|
@@ -53,11 +38,11 @@ RUN mkdir -p /tmp/mock_diffvg/pydiffvg && \
|
|
| 53 |
cd /tmp/mock_diffvg && \
|
| 54 |
pip install .
|
| 55 |
|
| 56 |
-
# Create a simple handler.py
|
| 57 |
-
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
COPY . .
|
| 61 |
|
| 62 |
# Set up the API
|
| 63 |
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /code
|
| 4 |
|
| 5 |
+
# Install system dependencies for Cairo
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
python3-dev \
|
| 9 |
+
libcairo2-dev \
|
| 10 |
pkg-config \
|
| 11 |
libpng-dev \
|
|
|
|
| 12 |
libffi-dev \
|
|
|
|
|
|
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
+
# Install torch 2.0.0 and torchvision 0.15.1
|
| 16 |
+
RUN pip install --no-cache-dir torch==2.0.0 torchvision==0.15.1
|
| 17 |
+
|
| 18 |
+
# Install cairosvg and its dependencies
|
| 19 |
+
RUN pip install --no-cache-dir cairosvg==2.7.0 cairocffi==1.5.1 cssselect2==0.7.0 defusedxml==0.7.1 tinycss2==1.2.1
|
| 20 |
+
|
| 21 |
+
# Install other dependencies
|
| 22 |
RUN pip install --no-cache-dir \
|
|
|
|
|
|
|
| 23 |
diffusers==0.15.1 \
|
| 24 |
transformers==4.27.4 \
|
| 25 |
accelerate==0.18.0 \
|
|
|
|
| 31 |
uvicorn==0.22.0 \
|
| 32 |
python-multipart==0.0.6
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Create mock diffvg package
|
| 35 |
RUN mkdir -p /tmp/mock_diffvg/pydiffvg && \
|
| 36 |
echo '# Mock diffvg package\nimport numpy as np\nimport torch\n\ndef render(shapes, shape_groups, width, height, samples=2, seed=None):\n return torch.zeros((height, width, 3), dtype=torch.float32)\n\ndef render_shape_group(canvas, shape_group_id, shapes, shape_groups, shape_ids, samples=2, seed=None):\n pass\n\ndef save_svg(shapes, shape_groups, filename, width, height, use_gamma=False, background=None):\n with open(filename, "w") as f:\n f.write(f"<svg width=\\"{width}\\" height=\\"{height}\\" xmlns=\\"http://www.w3.org/2000/svg\\"><rect width=\\"100%\\" height=\\"100%\\" fill=\\"white\\"/></svg>")\n\ndef svg_path_to_shapes(path_string):\n return [], []\n\ndef from_svg(filename):\n return [], []\n\nclass Circle:\n def __init__(self, radius=1.0, center=None):\n self.radius = radius\n self.center = center if center is not None else torch.tensor([0.0, 0.0])\n\nclass Ellipse:\n def __init__(self, radius=None, center=None):\n self.radius = radius if radius is not None else torch.tensor([1.0, 1.0])\n self.center = center if center is not None else torch.tensor([0.0, 0.0])\n\nclass Path:\n def __init__(self, points=None, is_closed=True):\n self.points = points if points is not None else torch.tensor([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])\n self.is_closed = is_closed\n\nclass Rect:\n def __init__(self, p_min=None, p_max=None):\n self.p_min = p_min if p_min is not None else torch.tensor([0.0, 0.0])\n self.p_max = p_max if p_max is not None else torch.tensor([1.0, 1.0])\n\nclass ShapeGroup:\n def __init__(self, shape_ids=None, fill_color=None, stroke_color=None):\n self.shape_ids = shape_ids if shape_ids is not None else []\n self.fill_color = fill_color if fill_color is not None else torch.tensor([1.0, 1.0, 1.0, 1.0])\n self.stroke_color = stroke_color if stroke_color is not None else torch.tensor([0.0, 0.0, 0.0, 1.0])' > /tmp/mock_diffvg/pydiffvg/__init__.py && \
|
|
|
|
| 38 |
cd /tmp/mock_diffvg && \
|
| 39 |
pip install .
|
| 40 |
|
| 41 |
+
# Create a simple handler.py
|
| 42 |
+
COPY handler.py /code/handler.py
|
| 43 |
|
| 44 |
+
# Create a simple API file
|
| 45 |
+
COPY api.py /code/api.py
|
| 46 |
|
| 47 |
# Set up the API
|
| 48 |
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
|