Skip to content

Commit

Permalink
Goofing around with some translation stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvolp12 committed Oct 1, 2024
1 parent f074687 commit d874cc3
Show file tree
Hide file tree
Showing 11 changed files with 3,465 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ object-detection-gpu-up:
@echo "Starting Object Detection API with GPU Acceleration..."
docker compose -f build/object-detection/gpu.docker-compose.yml up --build -d

# Build the Translation Python Service
.PHONY: translation-up
translation-up:
@echo "Starting Translation API..."
docker compose -f build/translation/docker-compose.yml up --build -d

# Build the Translation Analysis Python Service with GPU Acceleration
.PHONY: translation-gpu-up
translation-gpu-up:
@echo "Starting Translation API with GPU Acceleration..."
docker compose -f build/translation/gpu.docker-compose.yml up --build -d

# Build the Indexer Go binary
.PHONY: build-indexer
build-indexer:
Expand Down
35 changes: 35 additions & 0 deletions build/translation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Stage 1: Base layer with python and necessary libraries
FROM python:3.10-slim-buster as base

WORKDIR /app

COPY python/translation/poetry.lock python/translation/pyproject.toml /app/

RUN pip install poetry \
&& poetry config virtualenvs.create false \
&& poetry install --no-dev

RUN pip install torch==2.0.0+cpu torchvision==0.15.1+cpu torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cpu

# Stage 2: Downloading the translation model
FROM alpine/git:latest as model-downloader

WORKDIR /model

RUN git lfs install

RUN git clone https://hf.co/google-t5/t5-small

# Stage 3: Building the final image
FROM base as final

RUN mkdir -p /models

ENV MODEL_FROM_DISK=True
COPY --from=model-downloader /model/t5-small /app/google-t5/t5-small

COPY python/translation/translation /app/translation

ENV PYTHONPATH=/app

CMD ["uvicorn", "translation.app:app", "--host", "0.0.0.0", "--port", "8093"]
19 changes: 19 additions & 0 deletions build/translation/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'

services:
translation:
build:
context: ../../
dockerfile: build/translation/Dockerfile
extra_hosts:
- "host.docker.internal:host-gateway"
image: translation
restart: always
container_name: translation
env_file:
- ../../.env
environment:
- PORT=8093
ports:
- "8093:8093"

35 changes: 35 additions & 0 deletions build/translation/gpu.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Stage 1: Base layer with python and necessary libraries
FROM python:3.10-slim-buster as base

WORKDIR /app

COPY python/translation/poetry.lock python/translation/pyproject.toml /app/

RUN pip install poetry \
&& poetry config virtualenvs.create false \
&& poetry install --no-dev

RUN pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1

# Stage 2: Downloading the translation model
FROM alpine/git:latest as model-downloader

WORKDIR /model

RUN git lfs install

RUN git clone https://hf.co/google-t5/t5-small

# Stage 3: Building the final image
FROM base as final

RUN mkdir -p /models

ENV MODEL_FROM_DISK=True

COPY --from=model-downloader /model/t5-small /app/google-t5/t5-small
COPY python/translation/translation /app/translation

ENV PYTHONPATH=/app

CMD ["uvicorn", "translation.app:app", "--host", "0.0.0.0", "--port", "8093"]
25 changes: 25 additions & 0 deletions build/translation/gpu.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.8'

services:
translation:
build:
context: ../../
dockerfile: build/translation/gpu.Dockerfile
extra_hosts:
- "host.docker.internal:host-gateway"
image: translation
restart: always
container_name: translation
env_file:
- ../../.env
environment:
- PORT=8093
ports:
- "8093:8093"
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
Loading

0 comments on commit d874cc3

Please sign in to comment.