Skip to content

Commit 754039c

Browse files
authored
Merge pull request #21 from withoutbg/fix/docker-model-download
fix(docker): download model checkpoints from HuggingFace during build
2 parents 334967f + 62a2fed commit 754039c

4 files changed

Lines changed: 26 additions & 5 deletions

File tree

apps/web/Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,16 @@ RUN cd /app/packages/python && \
7373
# Copy backend application code
7474
COPY apps/web/backend/ ./backend/
7575

76-
# Copy ONNX model checkpoints
77-
COPY models/checkpoints/ ./checkpoints/
76+
# Download ONNX model checkpoints from Hugging Face
77+
RUN mkdir -p /app/checkpoints && \
78+
curl -fL --retry 3 -o /app/checkpoints/depth_anything_v2_vits_slim.onnx \
79+
"https://huggingface.co/withoutbg/focus/resolve/main/depth_anything_v2_vits_slim.onnx" && \
80+
curl -fL --retry 3 -o /app/checkpoints/isnet.onnx \
81+
"https://huggingface.co/withoutbg/focus/resolve/main/isnet.onnx" && \
82+
curl -fL --retry 3 -o /app/checkpoints/focus_matting_1.0.0.onnx \
83+
"https://huggingface.co/withoutbg/focus/resolve/main/focus_matting_1.0.0.onnx" && \
84+
curl -fL --retry 3 -o /app/checkpoints/focus_refiner_1.0.0.onnx \
85+
"https://huggingface.co/withoutbg/focus/resolve/main/focus_refiner_1.0.0.onnx"
7886

7987
# Copy built frontend from frontend builder to static directory
8088
COPY --from=frontend-builder /app/dist ./static

apps/web/backend/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FROM python:3.12-slim
2626
RUN apt-get update && \
2727
apt-get install -y --no-install-recommends \
2828
libgomp1 \
29+
curl \
2930
&& rm -rf /var/lib/apt/lists/*
3031

3132
# Set working directory
@@ -41,8 +42,16 @@ ENV PATH="/app/apps/web/backend/.venv/bin:/app/packages/python/.venv/bin:$PATH"
4142
# Copy application code
4243
COPY apps/web/backend/ ./backend/
4344

44-
# Copy ONNX model checkpoints
45-
COPY models/checkpoints/ ./checkpoints/
45+
# Download ONNX model checkpoints from Hugging Face
46+
RUN mkdir -p /app/checkpoints && \
47+
curl -fL --retry 3 -o /app/checkpoints/depth_anything_v2_vits_slim.onnx \
48+
"https://huggingface.co/withoutbg/focus/resolve/main/depth_anything_v2_vits_slim.onnx" && \
49+
curl -fL --retry 3 -o /app/checkpoints/isnet.onnx \
50+
"https://huggingface.co/withoutbg/focus/resolve/main/isnet.onnx" && \
51+
curl -fL --retry 3 -o /app/checkpoints/focus_matting_1.0.0.onnx \
52+
"https://huggingface.co/withoutbg/focus/resolve/main/focus_matting_1.0.0.onnx" && \
53+
curl -fL --retry 3 -o /app/checkpoints/focus_refiner_1.0.0.onnx \
54+
"https://huggingface.co/withoutbg/focus/resolve/main/focus_refiner_1.0.0.onnx"
4655

4756
# Set environment variables
4857
ENV PYTHONUNBUFFERED=1

apps/web/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ services:
2323
# Mount source code for hot-reload (correct path for Python 3.12 venv)
2424
- ../../packages/python/src/withoutbg:/app/apps/web/backend/.venv/lib/python3.12/site-packages/withoutbg:ro
2525
- ./backend:/app/backend:ro
26-
- ../../models/checkpoints:/app/checkpoints:ro
2726
working_dir: /app
2827
command: [ "/app/apps/web/backend/.venv/bin/python", "-m", "uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload" ]
2928
networks:

packages/python/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ select = [
107107

108108
[tool.mypy]
109109
python_version = "3.9"
110+
exclude = ["^\\.venv/"]
110111
warn_return_any = true
111112
warn_unused_configs = true
112113
disallow_untyped_defs = true
@@ -120,6 +121,10 @@ warn_no_return = true
120121
warn_unreachable = true
121122
strict_equality = true
122123

124+
[[tool.mypy.overrides]]
125+
module = ["huggingface_hub.*"]
126+
follow_imports = "skip"
127+
123128
[tool.pytest.ini_options]
124129
testpaths = ["tests"]
125130
python_files = ["test_*.py"]

0 commit comments

Comments
 (0)