From 8096f91d02d6c772eb77babe091a1fc06cf54c94 Mon Sep 17 00:00:00 2001
From: joecryptotoo <80373433+joecryptotoo@users.noreply.github.com>
Date: Thu, 22 Aug 2024 02:00:42 -0700
Subject: [PATCH] Dockerize (#22)

* created Dockerfile and docker-compose.yml

* Update docker-compose.yml

* added docker instructions to readme
---
 .dockerignore      |  6 ++++++
 .gitignore         |  3 ++-
 Dockerfile         | 13 +++++++++++++
 README.md          | 10 ++++++++++
 docker-compose.yml | 40 ++++++++++++++++++++++++++++++++++++++++
 requirements.txt   |  2 +-
 6 files changed, 72 insertions(+), 2 deletions(-)
 create mode 100644 .dockerignore
 create mode 100644 Dockerfile
 create mode 100644 docker-compose.yml

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..ccc1bdb
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,6 @@
+tmp
+cache
+Dockerfile
+docker-compose.yml
+.dockerignore
+.gitignore
diff --git a/.gitignore b/.gitignore
index 1767514..33b7875 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 __pycache__
-tmp
\ No newline at end of file
+tmp
+cache
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..774d406
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,13 @@
+FROM pytorch/pytorch:2.4.0-cuda12.1-cudnn9-devel
+
+ENV PYTHONUNBUFFERED 1
+
+WORKDIR /usr/src/app
+
+# Install packages
+RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
+
+COPY requirements.txt ./
+RUN pip install --no-cache-dir -r requirements.txt
+
+COPY . .
diff --git a/README.md b/README.md
index 822c765..6fdc484 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@
   - [Modularity](#modularity)
 * [Setup](#setup)
 * [Usage](#usage)
+  - [Docker Server approach](#docker-server)
   - [Server/Client approach](#serverclient-approach)
   - [Local approach](#local-approach)
 * [Command-line usage](#command-line-usage)
@@ -56,6 +57,15 @@ The pipeline can be run in two ways:
 - **Server/Client approach**: Models run on a server, and audio input/output are streamed from a client.
 - **Local approach**: Uses the same client/server method but with the loopback address.
 
+### Docker Server
+
+#### Install the NVIDIA Container Toolkit
+
+https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
+
+#### Start the docker container
+```docker compose up```
+
 ### Server/Client Approach
 
 To run the pipeline on the server:
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..ed2c9d4
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,40 @@
+---
+version: "3.8"
+services:
+
+  pipeline:
+    build:
+      context: .
+    command: 
+      - python3 
+      - s2s_pipeline.py 
+      - --recv_host 
+      - 0.0.0.0 
+      - --send_host 
+      - 0.0.0.0 
+      - --lm_model_name 
+      - microsoft/Phi-3-mini-4k-instruct 
+      - --init_chat_role 
+      - system
+      - --init_chat_prompt
+      - "You are a helpful assistant"
+      - --stt_compile_mode 
+      - reduce-overhead 
+      - --tts_compile_mode 
+      - default
+    expose:
+      - 12345/tcp
+      - 12346/tcp
+    ports:
+      - 12345:12345/tcp
+      - 12346:12346/tcp
+    volumes:
+      - ./cache/:/root/.cache/
+      - ./s2s_pipeline.py:/usr/src/app/s2s_pipeline.py
+    deploy:
+      resources:
+        reservations:
+          devices:
+            - driver: nvidia
+              device_ids: ['0']
+              capabilities: [gpu]
diff --git a/requirements.txt b/requirements.txt
index e04ebea..55985f8 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-nltk==3.8.1
+nltk==3.9.1
 parler_tts @ git+https://github.com/huggingface/parler-tts.git
 torch==2.4.0
 sounddevice==0.5.0
-- 
GitLab