davanstrien HF staff commited on
Commit
ff7e4c7
1 Parent(s): 18be176

chore: Add script to start Jupyter Lab server and copy notebooks to data directory

Browse files
Files changed (1) hide show
  1. start_server.sh +44 -0
start_server.sh ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Ensure /data exists and has the correct permissions
4
+ if [ ! -d /data ]; then
5
+ sudo mkdir -p /data
6
+ sudo chown user:user /data
7
+ fi
8
+
9
+ # Copy notebooks to /data, appending _UPDATED to filenames if they already exist
10
+ shopt -s globstar
11
+ for file in /home/user/notebooks/**/*; do
12
+ if [ -f "$file" ]; then
13
+ relative_path="${file#/home/user/notebooks/}"
14
+ target_file="/data/$relative_path"
15
+ target_dir=$(dirname "$target_file")
16
+ if [ ! -d "$target_dir" ]; then
17
+ mkdir -p "$target_dir"
18
+ fi
19
+ if [ -e "$target_file" ]; then
20
+ new_filename="${target_file%.*}_UPDATED.${target_file##*.}"
21
+ target_file="$new_filename"
22
+ fi
23
+ cp "$file" "$target_file"
24
+ fi
25
+ done
26
+
27
+ JUPYTER_TOKEN="${JUPYTER_TOKEN:=huggingface}"
28
+
29
+ echo "Starting Jupyter Lab with token $JUPYTER_TOKEN"
30
+
31
+ NOTEBOOK_DIR="/data"
32
+
33
+ jupyter-lab \
34
+ --ip 0.0.0.0 \
35
+ --port 7860 \
36
+ --no-browser \
37
+ --allow-root \
38
+ --ServerApp.token="$JUPYTER_TOKEN" \
39
+ --ServerApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" \
40
+ --ServerApp.cookie_options="{'SameSite': 'None', 'Secure': True}" \
41
+ --ServerApp.disable_check_xsrf=True \
42
+ --LabApp.news_url=None \
43
+ --LabApp.check_for_updates_class="jupyterlab.NeverCheckForUpdate" \
44
+ --notebook-dir=$NOTEBOOK_DIR