Skip to content
Snippets Groups Projects
Commit 25c3a1bd authored by Julian's avatar Julian
Browse files

first running version of dash inside of jupyterlab via proxy

parent aa96f462
No related branches found
No related tags found
2 merge requests!6Finalized Jupyterlab for the sprint,!1first running version of dash inside of jupyterlab via proxy
This commit is part of merge request !6. Comments created here will be created in the context of that merge request.
*env/
.env
FROM jupyter/datascience-notebook:hub-3.1.1
# Install from APT repository
USER root
RUN apt-get update -y
RUN apt-get install -y git
# Install basics
USER jovyan
RUN pip3 install --upgrade pip
COPY requirements.txt environment.yml /tmp/
RUN conda env update -q -f /tmp/environment.yml && \
/opt/conda/bin/pip install -r /tmp/requirements.txt && \
conda clean -y --all && \
conda env export -n "root" && \
jupyter lab build
COPY jupyter_notebook_config.py ${HOME}/.jupyter/
# copy dash app
COPY app ${HOME}/app/
RUN chown -R jovyan ${HOME}/app/
# RUN pip3 install --upgrade pip
RUN pip install jupyter-server-proxy==4.0.0
RUN pip install jupyterlab-git==0.42.0
RUN pip install jupyterlab-gitlab==3.0.0
# bücker
# A Jupyterlab for LLM
import sys
sys.path.append("/home/jovyan")
import argparse
import logging
from dash import Dash
from layout import layout
from callbacks import register_callbacks
logging.basicConfig(level=logging.INFO)
# get the correct port from proxy
parser = argparse.ArgumentParser()
parser.add_argument("--port", type=int)
args = parser.parse_args()
port: int = args.port
if not port:
raise ValueError(f"Port of proxy server for Dash not found in {args}.")
else:
logging.debug(f"Dash app running on port {port}.")
# define Dash app
app = Dash(
name=__name__,
requests_pathname_prefix="/dash/"
)
# define layout
app.layout = layout
# register all callback functions
register_callbacks(app=app)
# Run Dash app in the notebook
app.run(
jupyter_mode="jupyterlab",
port=port,
host="localhost",
debug=True
)
from dash import (
html,
Dash
)
from dash.dependencies import (
Input,
Output,
State
)
def register_callbacks(app: Dash):
@app.callback(
Output("output-container", "children"),
[Input("send-button", "n_clicks")],
[State("input-text", "value")]
)
def generate_response(n_clicks, input_text):
if n_clicks > 0:
response = "You said: " + input_text
return html.Div(response)
else:
return ""
from dash import (
html,
dcc
)
layout = html.Div(
className="container",
children=[
html.H1("GPT Chat", className="mt-5 mb-4"),
dcc.Textarea(id="input-text", placeholder="Enter your message:", className="form-control mb-3"),
html.Button("Send", id="send-button", n_clicks=0, className="btn btn-primary mb-3"),
html.Div(id="output-container")
]
)
name: "base"
channels:
- defaults
# dependencies:
# - add packages here
# - one per line
prefix: "/opt/conda"
# Configuration file for jupyter-notebook.
c.ServerProxy.servers = {
'dash': {
'command': [
'python',
'app/app.py',
'--port',
'{port}'
],
'absolute_url': False,
'new_browser_tab': False
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment