From 558bbe64c8806a45de5e39d20ee46db70da6d3d6 Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 04:16:20 +0000 Subject: [PATCH 01/10] Initial commit of dockerfile --- docker/pykoi-cpu/Dockerfile | 30 ++++++++++++++++++ docker/pykoi-gpu/Dockerfile | 46 ++++++++++++++++++++++++++++ example/chatbot/openai_model_demo.py | 6 ++-- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 docker/pykoi-cpu/Dockerfile create mode 100644 docker/pykoi-gpu/Dockerfile diff --git a/docker/pykoi-cpu/Dockerfile b/docker/pykoi-cpu/Dockerfile new file mode 100644 index 0000000..f08fc14 --- /dev/null +++ b/docker/pykoi-cpu/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:20.04 +LABEL maintainer="Pykio Team" +LABEL repository="Pykoi" + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt update && \ + apt install -y bash \ + build-essential \ + git \ + git-lfs \ + curl \ + ca-certificates \ + libsndfile1-dev \ + python3.8 \ + python3-pip \ + python3.8-venv && \ + rm -rf /var/lib/apt/lists + +# make sure to use venv +RUN python3 -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# pre-install the heavy dependencies (these can later be overridden by the deps from setup.py) +# follow the instructions here: https://cloud.google.com/tpu/docs/run-in-container#train_a_jax_model_in_a_docker_container +RUN python3 -m pip install --no-cache-dir --upgrade pip && \ + python3 -m pip install --upgrade --no-cache-dir \ + pykoi + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/docker/pykoi-gpu/Dockerfile b/docker/pykoi-gpu/Dockerfile new file mode 100644 index 0000000..143a838 --- /dev/null +++ b/docker/pykoi-gpu/Dockerfile @@ -0,0 +1,46 @@ +FROM ubuntu:20.04 +LABEL maintainer="Pykio Team" +LABEL repository="Pykoi" + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt update && \ + apt install -y bash \ + build-essential \ + git \ + git-lfs \ + curl \ + ca-certificates \ + libsndfile1-dev \ + python3.8 \ + python3-pip \ + libgl1 \ + python3.8-venv && \ + rm -rf /var/lib/apt/lists + +# make sure to use venv +RUN python3 -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# pre-install the heavy dependencies (these can later be overridden by the deps from setup.py) +RUN python3 -m pip install --no-cache-dir --upgrade pip && \ + python3 -m pip install --no-cache-dir \ + torch \ + torchvision \ + torchaudio && \ + python3 -m pip install --no-cache-dir \ + accelerate \ + datasets \ + hf-doc-builder \ + huggingface-hub \ + Jinja2 \ + librosa \ + numpy \ + scipy \ + tensorboard \ + transformers \ + omegaconf \ + pytorch-lightning \ + xformers + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/example/chatbot/openai_model_demo.py b/example/chatbot/openai_model_demo.py index 733acac..6f46654 100644 --- a/example/chatbot/openai_model_demo.py +++ b/example/chatbot/openai_model_demo.py @@ -5,7 +5,7 @@ # Creating an OpenAI model (requires an OpenAI API key) # ########################################################## # enter openai api key here -api_key = "" +api_key = "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" # Creating an OpenAI model model = pykoi.ModelFactory.create_model( @@ -25,7 +25,9 @@ ########################################################### # Create the application # app = pykoi.Application(debug=False, share=True) -app = pykoi.Application(debug=False, share=False) +app = pykoi.Application( + debug=False, + share=True) app.add_component(chatbot) app.add_component(dashboard) app.run() From d12f84e5f9cdbe1ea9949452848008e8b644bc94 Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 04:17:38 +0000 Subject: [PATCH 02/10] Initial commit of dockerfile --- docker/pykoi-gpu/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/pykoi-gpu/Dockerfile b/docker/pykoi-gpu/Dockerfile index 143a838..41d3b52 100644 --- a/docker/pykoi-gpu/Dockerfile +++ b/docker/pykoi-gpu/Dockerfile @@ -41,6 +41,7 @@ RUN python3 -m pip install --no-cache-dir --upgrade pip && \ transformers \ omegaconf \ pytorch-lightning \ - xformers + xformers \ + pykoi CMD ["/bin/bash"] \ No newline at end of file From 75b31ae6c805efe5a0941e7819171be00a6a394f Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 05:07:02 +0000 Subject: [PATCH 03/10] wip --- docker/README.md | 5 +++++ docker/pykoi-cpu-custom/Dockerfile | 13 ++++++++++++ docker/pykoi-cpu-custom/app.py | 34 ++++++++++++++++++++++++++++++ docker/pykoi-cpu/Dockerfile | 16 ++++++-------- gradio_test.py | 8 +++++++ 5 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 docker/README.md create mode 100644 docker/pykoi-cpu-custom/Dockerfile create mode 100644 docker/pykoi-cpu-custom/app.py create mode 100644 gradio_test.py diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..aa79db2 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,5 @@ +# Overview +In this folder, we create the different dockerfiles for using pykoi. + +1. `pykoi-cpu`: The base image for the cpu-based usage. +2. `pykoi-cpu-custom`: When you run this docker image, try to modify the `app.py` and mount it when running the docker container. \ No newline at end of file diff --git a/docker/pykoi-cpu-custom/Dockerfile b/docker/pykoi-cpu-custom/Dockerfile new file mode 100644 index 0000000..e7455f8 --- /dev/null +++ b/docker/pykoi-cpu-custom/Dockerfile @@ -0,0 +1,13 @@ +FROM weialexchen/pykoi-cpu:base + +# set the working directory in the container +WORKDIR /app + +# copy the content +COPY . /app + +# Expose the port on which the app will be running +EXPOSE 5000 + +# For dev +CMD ["python", "app.py"] \ No newline at end of file diff --git a/docker/pykoi-cpu-custom/app.py b/docker/pykoi-cpu-custom/app.py new file mode 100644 index 0000000..0717d6d --- /dev/null +++ b/docker/pykoi-cpu-custom/app.py @@ -0,0 +1,34 @@ +"""Demo for the chatbot application using OpenAI endpoint.""" +import pykoi + +########################################################## +# Creating an OpenAI model (requires an OpenAI API key) # +########################################################## +# enter openai api key here +api_key = "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" + +# Creating an OpenAI model +model = pykoi.ModelFactory.create_model( + model_source="openai", + api_key=api_key) + +##################################### +# Creating a chatbot with the model # +##################################### +database = pykoi.QuestionAnswerDatabase(debug=True) +chatbot = pykoi.Chatbot(model=model, feedback="vote") +# chatbot = pykoi.Chatbot(model=model, feedback="rank") +dashboard = pykoi.Dashboard(database=database) + +########################################################### +# Starting the application and add chatbot as a component # +########################################################### +# Create the application +# app = pykoi.Application(debug=False, share=True) +app = pykoi.Application( + host='0.0.0.0', + debug=False, + share=True) +app.add_component(chatbot) +app.add_component(dashboard) +app.run() diff --git a/docker/pykoi-cpu/Dockerfile b/docker/pykoi-cpu/Dockerfile index f08fc14..f6b5e32 100644 --- a/docker/pykoi-cpu/Dockerfile +++ b/docker/pykoi-cpu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM python:3.10 LABEL maintainer="Pykio Team" LABEL repository="Pykoi" @@ -11,20 +11,16 @@ RUN apt update && \ git-lfs \ curl \ ca-certificates \ - libsndfile1-dev \ - python3.8 \ - python3-pip \ - python3.8-venv && \ - rm -rf /var/lib/apt/lists + libsndfile1-dev # make sure to use venv -RUN python3 -m venv /opt/venv +RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" # pre-install the heavy dependencies (these can later be overridden by the deps from setup.py) # follow the instructions here: https://cloud.google.com/tpu/docs/run-in-container#train_a_jax_model_in_a_docker_container -RUN python3 -m pip install --no-cache-dir --upgrade pip && \ - python3 -m pip install --upgrade --no-cache-dir \ - pykoi +RUN python -m pip install --no-cache-dir --upgrade pip && \ + python -m pip install --upgrade --no-cache-dir \ + pykoi CMD ["/bin/bash"] \ No newline at end of file diff --git a/gradio_test.py b/gradio_test.py new file mode 100644 index 0000000..3080757 --- /dev/null +++ b/gradio_test.py @@ -0,0 +1,8 @@ +import gradio as gr + +def greet(name): + return "Hello " + name + "!" + +demo = gr.Interface(fn=greet, inputs="text", outputs="text") + +demo.launch() \ No newline at end of file From 37e73329ead1efd6049e04b8b82851b48b574fba Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 05:09:11 +0000 Subject: [PATCH 04/10] wip --- docker/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index aa79db2..5d44883 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,4 +2,11 @@ In this folder, we create the different dockerfiles for using pykoi. 1. `pykoi-cpu`: The base image for the cpu-based usage. -2. `pykoi-cpu-custom`: When you run this docker image, try to modify the `app.py` and mount it when running the docker container. \ No newline at end of file +2. `pykoi-cpu-custom`: When you run this docker image, try to modify the `app.py` and mount it when running the docker container. + +To run a docker container, we can use the following command: +```bash +docker run -dp 5000:5000 -v $(pwd)/app.py:/app/app.py \ + --name alex_test \ + weialexchen/pykoi-cpu:app +``` \ No newline at end of file From 1f3b0b7dcf740c3b452161608fbcf8bf02d51d5c Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 05:10:05 +0000 Subject: [PATCH 05/10] wip --- docker/pykoi-gpu/Dockerfile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/docker/pykoi-gpu/Dockerfile b/docker/pykoi-gpu/Dockerfile index 41d3b52..1b0ef34 100644 --- a/docker/pykoi-gpu/Dockerfile +++ b/docker/pykoi-gpu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM python:3.10 LABEL maintainer="Pykio Team" LABEL repository="Pykoi" @@ -12,11 +12,7 @@ RUN apt update && \ curl \ ca-certificates \ libsndfile1-dev \ - python3.8 \ - python3-pip \ - libgl1 \ - python3.8-venv && \ - rm -rf /var/lib/apt/lists + libgl1 # make sure to use venv RUN python3 -m venv /opt/venv From 558ec35dfd17fa1384ad3e2b330b8b59de87798c Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 05:11:40 +0000 Subject: [PATCH 06/10] wip --- docker/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index 5d44883..f11a21f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -9,4 +9,6 @@ To run a docker container, we can use the following command: docker run -dp 5000:5000 -v $(pwd)/app.py:/app/app.py \ --name alex_test \ weialexchen/pykoi-cpu:app -``` \ No newline at end of file +``` + +Note that we need to keep the exposed port as 5000 (default value) to make the server work. \ No newline at end of file From fc0fe9935adc669437e1cc412a5d53923120c199 Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 18:41:32 +0000 Subject: [PATCH 07/10] Fix the comment in last PR --- docker/pykoi-cpu-custom/Dockerfile | 4 ++-- docker/pykoi-cpu-custom/app.py | 1 - docker/pykoi-cpu/Dockerfile | 3 ++- example/chatbot/openai_model_demo.py | 4 +--- gradio_test.py | 8 -------- 5 files changed, 5 insertions(+), 15 deletions(-) delete mode 100644 gradio_test.py diff --git a/docker/pykoi-cpu-custom/Dockerfile b/docker/pykoi-cpu-custom/Dockerfile index e7455f8..f4431fa 100644 --- a/docker/pykoi-cpu-custom/Dockerfile +++ b/docker/pykoi-cpu-custom/Dockerfile @@ -1,4 +1,4 @@ -FROM weialexchen/pykoi-cpu:base +FROM pykoi/pykoi-cpu:base # set the working directory in the container WORKDIR /app @@ -10,4 +10,4 @@ COPY . /app EXPOSE 5000 # For dev -CMD ["python", "app.py"] \ No newline at end of file +CMD ["python", "app.py"] diff --git a/docker/pykoi-cpu-custom/app.py b/docker/pykoi-cpu-custom/app.py index 0717d6d..6f46654 100644 --- a/docker/pykoi-cpu-custom/app.py +++ b/docker/pykoi-cpu-custom/app.py @@ -26,7 +26,6 @@ # Create the application # app = pykoi.Application(debug=False, share=True) app = pykoi.Application( - host='0.0.0.0', debug=False, share=True) app.add_component(chatbot) diff --git a/docker/pykoi-cpu/Dockerfile b/docker/pykoi-cpu/Dockerfile index f6b5e32..6dfed62 100644 --- a/docker/pykoi-cpu/Dockerfile +++ b/docker/pykoi-cpu/Dockerfile @@ -23,4 +23,5 @@ RUN python -m pip install --no-cache-dir --upgrade pip && \ python -m pip install --upgrade --no-cache-dir \ pykoi -CMD ["/bin/bash"] \ No newline at end of file +CMD ["/bin/bash"] + diff --git a/example/chatbot/openai_model_demo.py b/example/chatbot/openai_model_demo.py index 6f46654..eea4484 100644 --- a/example/chatbot/openai_model_demo.py +++ b/example/chatbot/openai_model_demo.py @@ -25,9 +25,7 @@ ########################################################### # Create the application # app = pykoi.Application(debug=False, share=True) -app = pykoi.Application( - debug=False, - share=True) +app = pykoi.Application(debug=False, share=False) app.add_component(chatbot) app.add_component(dashboard) app.run() diff --git a/gradio_test.py b/gradio_test.py deleted file mode 100644 index 3080757..0000000 --- a/gradio_test.py +++ /dev/null @@ -1,8 +0,0 @@ -import gradio as gr - -def greet(name): - return "Hello " + name + "!" - -demo = gr.Interface(fn=greet, inputs="text", outputs="text") - -demo.launch() \ No newline at end of file From 08ce6be671d5df4db014f73bef48420fd0f88eef Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 18:41:47 +0000 Subject: [PATCH 08/10] Fix the comment in the PR --- docker/pykoi-gpu/Dockerfile | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/docker/pykoi-gpu/Dockerfile b/docker/pykoi-gpu/Dockerfile index 1b0ef34..8e07f3c 100644 --- a/docker/pykoi-gpu/Dockerfile +++ b/docker/pykoi-gpu/Dockerfile @@ -25,19 +25,7 @@ RUN python3 -m pip install --no-cache-dir --upgrade pip && \ torchvision \ torchaudio && \ python3 -m pip install --no-cache-dir \ - accelerate \ - datasets \ - hf-doc-builder \ - huggingface-hub \ - Jinja2 \ - librosa \ - numpy \ - scipy \ - tensorboard \ - transformers \ - omegaconf \ - pytorch-lightning \ - xformers \ pykoi -CMD ["/bin/bash"] \ No newline at end of file +CMD ["/bin/bash"] + From cd429b31ebe47dbdc9f5b1e7d159c80182b946b5 Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 18:44:08 +0000 Subject: [PATCH 09/10] Fix comment in the last PR --- docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index f11a21f..a2bb3a4 100644 --- a/docker/README.md +++ b/docker/README.md @@ -8,7 +8,7 @@ To run a docker container, we can use the following command: ```bash docker run -dp 5000:5000 -v $(pwd)/app.py:/app/app.py \ --name alex_test \ - weialexchen/pykoi-cpu:app + pykoi/pykoi-cpu:app ``` Note that we need to keep the exposed port as 5000 (default value) to make the server work. \ No newline at end of file From 19641f1af4daeff7ce2f0d3ce508bdbd2235d5c0 Mon Sep 17 00:00:00 2001 From: ALEX CHEN Date: Mon, 11 Sep 2023 18:45:09 +0000 Subject: [PATCH 10/10] Fix the comment in the last PR --- example/chatbot/openai_model_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/chatbot/openai_model_demo.py b/example/chatbot/openai_model_demo.py index eea4484..733acac 100644 --- a/example/chatbot/openai_model_demo.py +++ b/example/chatbot/openai_model_demo.py @@ -5,7 +5,7 @@ # Creating an OpenAI model (requires an OpenAI API key) # ########################################################## # enter openai api key here -api_key = "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" +api_key = "" # Creating an OpenAI model model = pykoi.ModelFactory.create_model(