Skip to content

Commit

Permalink
save to path on host instead of a volume
Browse files Browse the repository at this point in the history
  • Loading branch information
bkocis committed Aug 20, 2023
1 parent cf10202 commit dcffa3b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ cython_debug/
#.idea/
/chatgptApp/static/
/resources/simple-gradio-app
/chatgptApp/chat_sessions.db
/resources/chat_sessions.db
/chat_sessions.db
/resources/**
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ENV OPENAI_API_KEY $OPENAI_API_KEY
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONPATH /opt/chatgptApp

RUN mkdir /opt/app
RUN mkdir /opt/app && \
mkdir /opt/resources

COPY chatgptApp /opt/app
COPY ./requirements.txt /opt/app/requirements.txt
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PORT=8083
APP_NAME=openai-chatgpt-gradio-app
VOLUME_NAME=chat-sqlite3-volume-2
DB_PATH_ON_HOST=$(PATH_TO_DB)

build_test:
flake8 --config=.flake8
Expand All @@ -20,7 +21,8 @@ build_test:
docker run -p ${PORT}:${PORT} ${APP_NAME}
build_run:
docker build --tag=${APP_NAME} --build-arg OPENAI_API_KEY=${OPENAI_API_KEY} .
docker run -v ${VOLUME_NAME}:/opt/app -p ${PORT}:${PORT} ${APP_NAME}
# docker run -v ${VOLUME_NAME}:/opt/app -p ${PORT}:${PORT} ${APP_NAME}
docker run -v ${DB_PATH_ON_HOST}:/opt/resources -p ${PORT}:${PORT} -e PATH_TO_DB="/opt/resources" -it ${APP_NAME}
run_local:
docker run -v ${VOLUME_NAME}:/opt/app -p ${PORT}:${PORT} ${APP_NAME}

Expand All @@ -36,7 +38,8 @@ run_app:
python main.py
deploy_headless:
docker build --tag=${APP_NAME} --build-arg OPENAI_API_KEY=${OPENAI_API_KEY} .
docker run -dit -v ${VOLUME_NAME}:/opt/app -p ${PORT}:${PORT} ${APP_NAME}
# docker run -dit -v ${VOLUME_NAME}:/opt/app -p ${PORT}:${PORT} ${APP_NAME}
docker run -dit -v ${DB_PATH_ON_HOST}:/opt/resources -p ${PORT}:${PORT} -e PATH_TO_DB="/opt/resources" ${APP_NAME}
git_push:
flake8
git add .
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ deploy_headless:

Check the container with `docker logs`

Volumes and storage on host
When a docker volume is used, the data can be exported, or copied from the container:
```commandline
docker exec -it tender_bose /bin/bash
docker cp tender_bose:/opt/app/chat_sessions.db ./resources/
```

### Nginx

In case of deploying the app to your own server, you can use nginx for reverse proxy. Use the following endpoint block as a suggestion for the nginx config file:
Expand Down
5 changes: 3 additions & 2 deletions chatgptApp/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import logging
import sqlite3
import gradio as gr
Expand Down Expand Up @@ -80,7 +81,6 @@ def task():

def list_db_tab():
"""Returns data from an SQL query as a list of dicts."""
path_to_db = DB_NAME
select_query = "SELECT * FROM chat_session_01"
con = sqlite3.connect(path_to_db)
con.row_factory = sqlite3.Row
Expand Down Expand Up @@ -238,8 +238,9 @@ def main(system_message, human_message_prompt_template):

if __name__ == "__main__":
DB_NAME = "chat_sessions.db"
path_to_db = os.path.join(os.environ["PATH_TO_DB"], DB_NAME)

conn = sqlite3.connect(DB_NAME, check_same_thread=False)
conn = sqlite3.connect(path_to_db, check_same_thread=False)
c = conn.cursor()
# create a table to store the chat sessions
c.execute("CREATE TABLE IF NOT EXISTS chat_session_01 (id INTEGER PRIMARY KEY, question TEXT, answer TEXT)")
Expand Down

0 comments on commit dcffa3b

Please sign in to comment.