From fc75c15630f5dfbb8ef7381dbaf146516f7ab067 Mon Sep 17 00:00:00 2001 From: Julian <julian@edyoucated.org> Date: Mon, 11 Mar 2024 20:13:17 +0100 Subject: [PATCH] configure dash proxy entrypoint via simple py_module --- Dockerfile | 8 +++----- README.md | 2 +- app/app.py | 5 +++-- client.py => app/client.py | 0 dash_proxy.py | 25 +++++++++++++++++++++++++ jupyter_notebook_config.py | 13 ------------- setup.py | 16 ++++++++++++++++ 7 files changed, 48 insertions(+), 21 deletions(-) rename client.py => app/client.py (100%) create mode 100644 dash_proxy.py delete mode 100644 jupyter_notebook_config.py create mode 100644 setup.py diff --git a/Dockerfile b/Dockerfile index 595ec0e..273811c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +9,10 @@ RUN conda env update -q -f /tmp/environment.yml && \ conda env export -n "root" && \ jupyter lab build -COPY jupyter_notebook_config.py ${HOME}/.jupyter/ +COPY dash_proxy.py setup.py /tmp/dash_proxy/ +RUN pip3 install --upgrade pip +RUN pip install /tmp/dash_proxy/ # copy dash app COPY app ${HOME}/app/ RUN chown -R jovyan ${HOME}/app/ - -COPY client.py ${HOME}/ -RUN chown -R jovyan ${HOME}/client.py - diff --git a/README.md b/README.md index 2c4caf3..ef4faa6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # A Jupyterlab for LLM -AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, OPENAI_API_VERSION need to be stored in a config.txt file in the home directory. +In order to run Dash or use the client, AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, OPENAI_API_VERSION need to be stored in a config.txt file in the home directory. diff --git a/app/app.py b/app/app.py index 4975d67..4492011 100644 --- a/app/app.py +++ b/app/app.py @@ -1,5 +1,6 @@ +import os import sys -sys.path.append("/home/jovyan") +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import argparse import logging @@ -26,7 +27,7 @@ else: # define Dash app app = Dash( name=__name__, - requests_pathname_prefix="/dash/" + requests_pathname_prefix="/Dash/" ) # define layout diff --git a/client.py b/app/client.py similarity index 100% rename from client.py rename to app/client.py diff --git a/dash_proxy.py b/dash_proxy.py new file mode 100644 index 0000000..b7add29 --- /dev/null +++ b/dash_proxy.py @@ -0,0 +1,25 @@ +import os +import logging + +logger = logging.getLogger(__name__) +logger.setLevel('INFO') + +HERE = os.path.dirname(os.path.abspath(__file__)) + + +def setup_dash_proxy(): + command = [ + 'python', + 'app/app.py', + '--port', + '{port}' + ] + + return { + "command": command, + "new_browser_tab": False, + "launcher_entry": { + "enabled": True, + 'title': 'Dash' + } + } diff --git a/jupyter_notebook_config.py b/jupyter_notebook_config.py deleted file mode 100644 index 22208d3..0000000 --- a/jupyter_notebook_config.py +++ /dev/null @@ -1,13 +0,0 @@ -# Configuration file for jupyter-notebook. -c.ServerProxy.servers = { - 'dash': { - 'command': [ - 'python', - 'app/app.py', - '--port', - '{port}' - ], - 'absolute_url': False, - 'new_browser_tab': False - } -} diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ccd874c --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +import setuptools + +setuptools.setup( + author="Julian Rasch", + author_email="julian.rasch@fh-muenster.de", + description="A small module to run Dash inside a dockerized Jupyterlab.", + name="jupyter-dash-proxy", + py_modules=["dash_proxy"], + entry_points={ + "jupyter_serverproxy_servers": [ + # name = packagename:function_name + "Dash = dash_proxy:setup_dash_proxy", + ] + }, + install_requires=["jupyter-server-proxy==4.0.0"], +) -- GitLab