File size: 3,197 Bytes
23230e6
 
 
0913112
23230e6
13c3930
 
23230e6
13c3930
f1df83f
13c3930
 
299bd84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13c3930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0913112
 
13c3930
 
 
 
f1df83f
 
 
13c3930
 
0913112
 
 
23230e6
 
 
 
 
 
 
 
 
 
 
 
 
0913112
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
JUPYTER_TOKEN="${JUPYTER_TOKEN:=huggingface}"

# Define directories
NOTEBOOK_DIR="/data"
ORIGINAL_NOTEBOOKS="/home/user/app/notebooks"  # Path where notebooks are located
ORIGINAL_IMAGES="/home/user/app/notebooks/images"  # Path where images are located

echo "Starting notebook and images setup process..."

# Set up notebooks
echo "Looking for notebooks in: $ORIGINAL_NOTEBOOKS"
find "$ORIGINAL_NOTEBOOKS" -name "*.ipynb" -type f 2>/dev/null || echo "Cannot find notebooks in $ORIGINAL_NOTEBOOKS"

# Check if we can find the notebooks
if ls "$ORIGINAL_NOTEBOOKS"/*.ipynb 1> /dev/null 2>&1; then
    echo "Found notebooks in $ORIGINAL_NOTEBOOKS"
    
    # Clear the notebook directory and copy fresh notebooks for this session
    echo "Preparing fresh notebooks for this session..."
    mkdir -p "$NOTEBOOK_DIR"
    rm -f "$NOTEBOOK_DIR"/*.ipynb
    
    # Copy notebooks to data directory
    cp -v "$ORIGINAL_NOTEBOOKS"/*.ipynb "$NOTEBOOK_DIR/" || echo "Failed to copy notebooks"
else
    echo "No notebooks found in expected location. Checking all directories..."
    find / -name "*.ipynb" -not -path "*/\.*" 2>/dev/null | head -10
fi

# Set up images directory
echo "Looking for images in: $ORIGINAL_IMAGES"
IMAGES_DIR="$NOTEBOOK_DIR/images"

# Create images directory in data
mkdir -p "$IMAGES_DIR"
rm -f "$IMAGES_DIR"/*.png "$IMAGES_DIR"/*.jpg "$IMAGES_DIR"/*.jpeg "$IMAGES_DIR"/*.gif

# Check if original images directory exists
if [ -d "$ORIGINAL_IMAGES" ]; then
    echo "Found images directory at $ORIGINAL_IMAGES"
    
    # Copy all image files to the images directory in data
    find "$ORIGINAL_IMAGES" -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.gif" \) -exec cp -v {} "$IMAGES_DIR/" \; || echo "Failed to copy images"
else
    echo "No images directory found at $ORIGINAL_IMAGES. Checking alternatives..."
    # Try to find images in other possible locations
    if [ -d "/home/user/app/images" ]; then
        echo "Found images in /home/user/app/images"
        find "/home/user/app/images" -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.gif" \) -exec cp -v {} "$IMAGES_DIR/" \; || echo "Failed to copy images"
    else
        echo "No images directory found. Creating an empty one."
    fi
fi

# Set proper permissions
chmod -R 755 "$NOTEBOOK_DIR"
chown -R $(whoami) "$NOTEBOOK_DIR" 2>/dev/null || echo "Could not change ownership"

# Show what we've got
echo "Contents of notebook directory ($NOTEBOOK_DIR):"
ls -la "$NOTEBOOK_DIR"
echo "Contents of images directory ($IMAGES_DIR):"
ls -la "$IMAGES_DIR"

# Start JupyterLab
echo "Starting JupyterLab..."
jupyter labextension disable "@jupyterlab/apputils-extension:announcements"

jupyter-lab \
    --ip 0.0.0.0 \
    --port 7860 \
    --no-browser \
    --allow-root \
    --ServerApp.token="$JUPYTER_TOKEN" \
    --ServerApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" \
    --ServerApp.cookie_options="{'SameSite': 'None', 'Secure': True}" \
    --ServerApp.disable_check_xsrf=True \
    --LabApp.news_url=None \
    --LabApp.check_for_updates_class="jupyterlab.NeverCheckForUpdate" \
    --notebook-dir=$NOTEBOOK_DIR