Skip to content

Commit 849bbf2

Browse files
committed
Adding docker files
1 parent 72bbafe commit 849bbf2

6 files changed

Lines changed: 157 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
### 0.0.6
4+
### Added
5+
* Added dockerfiles and database export and import functionality.
6+
37
### 0.0.5
48
### Fixed
59
* Moved context window to only be handled on an LLM-level.

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM python
2+
3+
WORKDIR /app
4+
5+
# nlp_pipeline requirements
6+
# install poppler, tesseract, antiword
7+
RUN apt-get update
8+
RUN apt-get install poppler-utils -y
9+
RUN apt-get install tesseract-ocr -y
10+
RUN apt-get install antiword
11+
12+
# postgres
13+
RUN apt-get install -y postgresql-common
14+
RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
15+
RUN apt-get update
16+
ARG DEBIAN_FRONTEND=noninteractive
17+
RUN apt-get purge postgresql-
18+
RUN apt-get install -y postgresql-16
19+
RUN apt-get install -y postgresql-client
20+
21+
# nlp_pipeline libraries
22+
RUN pip install -r https://raw.githubusercontent.com/dhopp1/nlp_pipeline/main/requirements.txt
23+
RUN pip install --ignore-installed six
24+
RUN pip install nlp-pipeline
25+
26+
# local_rag_llm requirements
27+
RUN pip install -r https://raw.githubusercontent.com/dhopp1/local_rag_llm/main/requirements.txt
28+
RUN pip install local-rag-llm
29+
30+
# clone streamlit app
31+
RUN git clone https://github.com/dhopp1/streamlit_rag.git
32+
RUN pip install gnews
33+
# exclude gnews because of requests dependency
34+
RUN curl -s https://raw.githubusercontent.com/dhopp1/streamlit_rag/main/requirements.txt | grep -v gnews | xargs pip install

Dockerfile-gpu

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM nvidia/cuda:12.4.1-devel-ubuntu22.04
2+
3+
WORKDIR /app
4+
5+
# install python
6+
RUN apt-get update
7+
RUN apt-get install -y curl git python3-pip python3-dev python-is-python3
8+
RUN rm -rf /var/lib/apt/lists/*
9+
10+
# nlp_pipeline requirements
11+
RUN apt-get update
12+
RUN apt-get install poppler-utils -y
13+
RUN apt-get install tesseract-ocr -y
14+
RUN apt-get install antiword
15+
16+
# postgres
17+
RUN apt-get install -y postgresql-common
18+
RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
19+
RUN apt-get update
20+
ARG DEBIAN_FRONTEND=noninteractive
21+
RUN apt-get purge postgresql-
22+
RUN apt-get install -y postgresql-16
23+
RUN apt-get install -y postgresql-client
24+
25+
# nlp_pipeline libraries
26+
RUN pip install -r https://raw.githubusercontent.com/dhopp1/nlp_pipeline/main/requirements.txt
27+
RUN pip install --ignore-installed six
28+
RUN pip install nlp-pipeline
29+
30+
# local_rag_llm requirements
31+
ENV CMAKE_ARGS="-DLLAMA_CUBLAS=ON"
32+
RUN pip install -r https://raw.githubusercontent.com/dhopp1/local_rag_llm/main/requirements.txt
33+
RUN pip install local-rag-llm
34+
35+
# clone streamlit app
36+
RUN git clone https://github.com/dhopp1/streamlit_rag.git
37+
RUN pip install gnews
38+
# exclude gnews because of requests dependency
39+
RUN curl -s https://raw.githubusercontent.com/dhopp1/streamlit_rag/main/requirements.txt | grep -v gnews | xargs pip install

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,28 @@ secondaryBackgroundColor="#F0F2F6"
6060

6161
## Example image
6262
![Example image](metadata/example_screen.png)
63+
64+
## Docker usage
65+
### CPU only and CUDA
66+
If only using the CPU or an Nvidia GPU, you can run the application exclusively with Docker.
67+
68+
- Download the `docker-compose.yml` and `Dockerfile` (for CPU-only) or `Dockerfile-gpu` (for GPU) files
69+
- In `docker-compose.yml`, edit the HF_TOKEN to your API token
70+
- There are four elements which need to exist outside of the container for persistence, portability, and personalization:
71+
- **`corpora/` directory**: this is where processed corpora (text files and vector database dumps) are saved. Change the `<local corpora directory>` line in `docker-compose.yml` to your local path for these files.
72+
- **`metadata/` directory**: this is where various information like database credentials, user list, llm list, etc. are stored. Change the `<local metadata directory>` line in `docker-compose.yml` to your local path for these files. The elements to be manually checked and changed are `db_creds.csv`, the `app_title`, `author_name`, and `author_email` columns, `llm_list.csv`, and `user_list.csv`.
73+
- **`models/` directory**: this is where the actual LLMs are stored. Change the `<local models directory>` line in `docker-compose.yml` to your local path for these files.
74+
- **`secrets.toml` file**: this is where you can change the application's password. Change the `<local secrets.toml file path>` line in `docker-compose.yml` to your local path for this file.
75+
- If you are using the CPU, delete or comment out the `deploy:` section in `docker-compose.yml`, and change the `dockerfile: Dockerfile-gpu` line to `dockerfile: Dockerfile`.
76+
- Navigate to the directory where you saved the `docker-compose.yml` file and Dockerfile and run `docker compose up`
77+
- The application will now be available on port 8502 by default.
78+
79+
### Apple silicon
80+
If you are using Apple silicon, you won't be able to run everything in Docker because of the lack of MPS drivers. You can still use the pgvector image however.
81+
82+
- follow the instructions to install [local\_rag\_llm](https://github.com/dhopp1/local_rag_llm/) and [nlp\_pipeline](https://github.com/dhopp1/nlp_pipeline) individually
83+
- Download the `docker-compose.yml` file
84+
- From the `docker-compose.yml` file, delete the `streamlit:` line and everything below it
85+
- Start the postgres container with `docker compose up`
86+
- Edit your `metadata/db_creds.csv` file and change the `host` column from `localhost` to `postgres` and `username` to `postgres`
87+
- Run the application as normal.

docker-compose.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
postgres:
3+
image: pgvector/pgvector:pg16
4+
environment:
5+
POSTGRES_PASSWORD: secret
6+
POSTGRES_USER: postgres
7+
POSTGRES_DB: postgres
8+
expose:
9+
- 5432
10+
ports:
11+
- 5432:5432
12+
streamlit:
13+
build:
14+
dockerfile: Dockerfile-gpu
15+
environment:
16+
HF_TOKEN: <HF API token>
17+
depends_on:
18+
- postgres
19+
deploy:
20+
resources:
21+
reservations:
22+
devices:
23+
- driver: nvidia
24+
capabilities: [gpu]
25+
count: 'all'
26+
working_dir: /app/streamlit_rag
27+
ports:
28+
- 8502:8502
29+
volumes:
30+
- <local corpora directory>:/app/streamlit_rag/corpora
31+
- <local metadata directory>:/app/streamlit_rag/metadata
32+
- <local models directory>:/app/streamlit_rag/models
33+
- <local secret.toml file path>:/app/streamlit_rag/.streamlit/secrets.toml
34+
command: ["streamlit", "run", "app.py", "--server.port=8502", "--server.address=0.0.0.0"]

helper/clear_corpus.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,29 @@
77
from psycopg2 import sql
88
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
99

10-
from own_corpus import check_db_exists
11-
1210
# standalone script to clear out corpora. Run standalone directly from the helper/ directory
1311
# ex: python clear_corpus --keep corpus1,corpus1 | python clear_corpus --remove corpus1,corpus2
1412

1513

14+
def check_db_exists(host, port, user, password, db_name):
15+
"check if a database exists"
16+
conn = psycopg2.connect(
17+
f"host={host} port={port} dbname=postgres user={user} password={password}"
18+
)
19+
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
20+
cur = conn.cursor()
21+
22+
cur.execute(sql.SQL("SELECT datname FROM pg_database WHERE datistemplate = false;"))
23+
dbs = cur.fetchall()
24+
25+
result = db_name in [x[0] for x in dbs]
26+
27+
cur.close()
28+
conn.close()
29+
30+
return result
31+
32+
1633
def parse_list(arg):
1734
return arg.split(",")
1835

@@ -46,8 +63,9 @@ def clear_corpus(keep=[], remove=[]):
4663
):
4764
# establish connection
4865
conn = psycopg2.connect(
49-
f"dbname=vector_db user={db_info.loc[0, 'user']} password={db_info.loc[0, 'password']}"
66+
f"""host={db_info.loc[lambda x: x.field == "host", "value"].values[0]} port={db_info.loc[lambda x: x.field == "port", "value"].values[0]} dbname={db_info.loc[lambda x: x.field == "master_db_name", "value"].values[0]} user={db_info.loc[lambda x: x.field == "user", "value"].values[0]} password={db_info.loc[lambda x: x.field == "password", "value"].values[0]}"""
5067
)
68+
5169
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
5270
cur = conn.cursor()
5371

0 commit comments

Comments
 (0)