Skip to content

Commit 1e145fe

Browse files
committed
feat: enhance Docker setup with entrypoint script and model downloads
1 parent 82baaf6 commit 1e145fe

File tree

12 files changed

+167
-32
lines changed

12 files changed

+167
-32
lines changed

tree-disk-api/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ docker.compose.yml
3333
output/
3434
input/
3535
tests/
36+
models/

tree-disk-api/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ COPY --from=builder /app/.venv .venv
3838
# Copy application code
3939
COPY . .
4040

41+
# Add the source directory to PYTHONPATH so imports resolve correctly
42+
ENV PYTHONPATH="/app/src"
43+
44+
# Copy the entrypoint script into the image and set execute permission
45+
COPY entrypoint.sh /entrypoint.sh
46+
RUN chmod +x /entrypoint.sh
47+
4148
# Activate virtual environment
4249
ENV PATH="/app/.venv/bin:$PATH"
4350

4451
EXPOSE 3100
4552

46-
CMD ["gunicorn", "main:app", "-c", "gunicorn.conf.py"]
53+
ENTRYPOINT ["/entrypoint.sh"]

tree-disk-api/entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Downloading models..."
5+
python src/config/preparation.py
6+
7+
echo "Starting server..."
8+
exec gunicorn main:app -c gunicorn.conf.py

tree-disk-api/poetry.lock

Lines changed: 75 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tree-disk-api/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ python-multipart = "^0.0.17"
1616
tree-disk-segmentation = "^0.1.3"
1717
tree-disk-pith = "^0.1.4"
1818
tree-disk-rings = "^0.4.5"
19+
gdown = "^5.2.0"
1920

2021
[poetry.group.dev.dependencies]
2122
tree-disk-segmentation = { path = "../tree-disk-segmentation" }

tree-disk-api/src/api/endpoints/pith.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from PIL import Image
55
import io
66

7-
from config import OUTPUT_DIR, INPUT_DIR, YOLO_MODEL_PATH, DEBUG, SAVE_RESULTS
7+
from config.settings import OUTPUT_DIR, INPUT_DIR, YOLO_MODEL_PATH, DEBUG, SAVE_RESULTS
88

99
router = APIRouter()
1010

tree-disk-api/src/api/endpoints/rings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io
55
from io import BytesIO
66

7-
from config import OUTPUT_DIR, INPUT_DIR, DEBUG, SAVE_RESULTS
7+
from config.settings import OUTPUT_DIR, INPUT_DIR, DEBUG, SAVE_RESULTS
88

99
router = APIRouter()
1010

tree-disk-api/src/api/endpoints/segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io
55
from io import BytesIO
66

7-
from config import OUTPUT_DIR, INPUT_DIR, U2NET_MODEL_PATH, DEBUG, SAVE_RESULTS
7+
from config.settings import OUTPUT_DIR, INPUT_DIR, U2NET_MODEL_PATH, DEBUG, SAVE_RESULTS
88

99
router = APIRouter()
1010

tree-disk-api/src/config.py

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import logging
2+
import gdown
3+
from config.settings import (
4+
INPUT_DIR,
5+
OUTPUT_DIR,
6+
MODEL_PATH,
7+
U2NET_MODEL_PATH,
8+
YOLO_MODEL_PATH,
9+
)
10+
11+
logger = logging.getLogger(__name__)
12+
13+
14+
def download_u2net_model():
15+
"""
16+
Download the model from Google Drive.
17+
"""
18+
file_id = "1ao1ovG1Qtx4b7EoskHXmi2E9rp5CHLcZ"
19+
url = f"https://drive.google.com/uc?id={file_id}"
20+
21+
logger.info(f"Downloading Google Drive file from: {url}")
22+
23+
gdown.download(url, str(U2NET_MODEL_PATH), quiet=False)
24+
25+
26+
def download_yolo_model():
27+
"""
28+
Download the model from Google Drive.
29+
"""
30+
file_id = "1_-dDH4DNiL8wbgiPWPaNqne7kbJyZc8z"
31+
url = f"https://drive.google.com/uc?id={file_id}"
32+
33+
logger.info(f"Downloading Google Drive file from: {url}")
34+
35+
gdown.download(url, str(YOLO_MODEL_PATH), quiet=False)
36+
37+
38+
def create_dirs():
39+
"""
40+
Create necessary directories if they do not exist.
41+
"""
42+
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
43+
INPUT_DIR.mkdir(parents=True, exist_ok=True)
44+
MODEL_PATH.mkdir(parents=True, exist_ok=True)
45+
46+
47+
create_dirs()
48+
download_u2net_model()
49+
download_yolo_model()

0 commit comments

Comments
 (0)