Evgueni Poloukarov commited on
Commit
8429ece
·
1 Parent(s): 2cc71b4

fix: use official HuggingFace JupyterLab Docker template

Browse files

- Complete rewrite using HF official template configuration
- Uses nvidia/cuda base image with miniconda
- Proper iframe embedding with CSP and cookie settings
- Starts notebooks from /data directory
- Password: huggingface (default)

Files changed (6) hide show
  1. Dockerfile +89 -32
  2. README.md +4 -3
  3. on_startup.sh +3 -0
  4. packages.txt +0 -0
  5. requirements.txt +4 -7
  6. start_server.sh +20 -0
Dockerfile CHANGED
@@ -1,34 +1,91 @@
1
- # Official Jupyter PyTorch notebook with CUDA 12 (HF Spaces recommended)
2
- FROM quay.io/jupyter/pytorch-notebook:cuda12-latest
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- # Switch to root for system packages
5
  USER root
6
- RUN apt-get update && apt-get install -y git curl wget && \
7
- rm -rf /var/lib/apt/lists/*
8
-
9
- # Switch back to jovyan user (uid 1000)
10
- USER jovyan
11
- WORKDIR /home/jovyan
12
-
13
- # Install Python dependencies
14
- COPY --chown=jovyan:users requirements.txt .
15
- RUN pip install --no-cache-dir -r requirements.txt
16
-
17
- # Copy notebooks and source code
18
- COPY --chown=jovyan:users *.ipynb ./
19
- COPY --chown=jovyan:users src/ ./src/
20
-
21
- # Expose JupyterLab port
22
- EXPOSE 7860
23
-
24
- # Start JupyterLab with HF Spaces configuration
25
- CMD ["jupyter", "lab", \
26
- "--ip=0.0.0.0", \
27
- "--port=7860", \
28
- "--no-browser", \
29
- "--ServerApp.token=''", \
30
- "--ServerApp.password=''", \
31
- "--ServerApp.base_url=/", \
32
- "--ServerApp.allow_origin='*'", \
33
- "--ServerApp.allow_remote_access=True", \
34
- "--ServerApp.disable_check_xsrf=True"]
 
1
+ FROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ TZ=Europe/Paris
5
+
6
+ # Remove any third-party apt sources to avoid issues with expiring keys.
7
+ # Install some basic utilities
8
+ RUN rm -f /etc/apt/sources.list.d/*.list && \
9
+ apt-get update && apt-get install -y --no-install-recommends \
10
+ curl \
11
+ ca-certificates \
12
+ sudo \
13
+ git \
14
+ wget \
15
+ procps \
16
+ git-lfs \
17
+ zip \
18
+ unzip \
19
+ htop \
20
+ vim \
21
+ nano \
22
+ bzip2 \
23
+ libx11-6 \
24
+ build-essential \
25
+ libsndfile-dev \
26
+ software-properties-common \
27
+ && rm -rf /var/lib/apt/lists/*
28
+
29
+ RUN add-apt-repository ppa:flexiondotorg/nvtop && \
30
+ apt-get upgrade -y && \
31
+ apt-get install -y --no-install-recommends nvtop
32
+
33
+ RUN curl -sL https://deb.nodesource.com/setup_21.x | bash - && \
34
+ apt-get install -y nodejs && \
35
+ npm install -g configurable-http-proxy
36
+
37
+ WORKDIR /app
38
+
39
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
40
+ && chown -R user:user /app
41
+
42
+ RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
43
+
44
+ USER user
45
+
46
+ ENV HOME=/home/user
47
+
48
+ RUN mkdir $HOME/.cache $HOME/.config \
49
+ && chmod -R 777 $HOME
50
+
51
+ ENV CONDA_AUTO_UPDATE_CONDA=false \
52
+ PATH=$HOME/miniconda/bin:$PATH
53
+
54
+ RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \
55
+ && chmod +x ~/miniconda.sh \
56
+ && ~/miniconda.sh -b -p ~/miniconda \
57
+ && rm ~/miniconda.sh \
58
+ && conda clean -ya
59
+
60
+ WORKDIR $HOME/app
61
 
 
62
  USER root
63
+
64
+ RUN --mount=target=/root/packages.txt,source=packages.txt \
65
+ apt-get update && \
66
+ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
67
+ && rm -rf /var/lib/apt/lists/*
68
+
69
+ RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
70
+ bash /root/on_startup.sh
71
+
72
+ RUN mkdir /data && chown user:user /data
73
+
74
+ USER user
75
+
76
+ RUN --mount=target=requirements.txt,source=requirements.txt \
77
+ pip install --no-cache-dir --upgrade -r requirements.txt
78
+
79
+ COPY --chown=user . $HOME/app
80
+
81
+ RUN chmod +x start_server.sh
82
+
83
+ ENV PYTHONUNBUFFERED=1 \
84
+ GRADIO_ALLOW_FLAGGING=never \
85
+ GRADIO_NUM_PORTS=1 \
86
+ GRADIO_SERVER_NAME=0.0.0.0 \
87
+ GRADIO_THEME=huggingface \
88
+ SYSTEM=spaces \
89
+ SHELL=/bin/bash
90
+
91
+ CMD ["./start_server.sh"]
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
- title: FBMC Chronos-2 Zero-Shot Forecasting
3
  emoji: ⚡
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: docker
7
- app_port: 7860
8
  pinned: false
9
- license: mit
 
 
10
  ---
11
 
12
  # FBMC Flow-Based Market Coupling Forecasting
 
1
  ---
2
+ title: FBMC Chronos-2 Forecasting
3
  emoji: ⚡
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: docker
 
7
  pinned: false
8
+ tags:
9
+ - jupyterlab
10
+ suggested_storage: small
11
  ---
12
 
13
  # FBMC Flow-Based Market Coupling Forecasting
on_startup.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Startup script - runs as root before container starts
packages.txt ADDED
File without changes
requirements.txt CHANGED
@@ -1,5 +1,7 @@
1
- # HuggingFace Space Requirements for FBMC Chronos-2 Forecasting
2
- # GPU-optimized dependencies for JupyterLab SDK
 
 
3
 
4
  # Core ML/Data
5
  torch>=2.0.0
@@ -16,11 +18,6 @@ huggingface-hub>=0.19.0
16
  altair>=5.0.0
17
  vega-datasets
18
 
19
- # Jupyter
20
- ipykernel
21
- jupyter
22
- jupyterlab
23
-
24
  # Utilities
25
  python-dotenv
26
  tqdm
 
1
+ # JupyterLab (from HF template)
2
+ jupyterlab==4.2.5
3
+ tornado==6.2
4
+ ipywidgets
5
 
6
  # Core ML/Data
7
  torch>=2.0.0
 
18
  altair>=5.0.0
19
  vega-datasets
20
 
 
 
 
 
 
21
  # Utilities
22
  python-dotenv
23
  tqdm
start_server.sh ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ JUPYTER_TOKEN="${JUPYTER_TOKEN:=huggingface}"
4
+
5
+ NOTEBOOK_DIR="/data"
6
+
7
+ jupyter labextension disable "@jupyterlab/apputils-extension:announcements"
8
+
9
+ jupyter-lab \
10
+ --ip 0.0.0.0 \
11
+ --port 7860 \
12
+ --no-browser \
13
+ --allow-root \
14
+ --ServerApp.token="$JUPYTER_TOKEN" \
15
+ --ServerApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" \
16
+ --ServerApp.cookie_options="{'SameSite': 'None', 'Secure': True}" \
17
+ --ServerApp.disable_check_xsrf=True \
18
+ --LabApp.news_url=None \
19
+ --LabApp.check_for_updates_class="jupyterlab.NeverCheckForUpdate" \
20
+ --notebook-dir=$NOTEBOOK_DIR