├── .github
└── workflows
│ ├── sync_app_with_spaces.yml
│ ├── sync_jupyterlab_gpu_with_spaces.yml
│ └── sync_vscode_gpu_with_spaces.yml
├── .gitignore
├── README.md
├── app
├── app.py
└── style.css
├── jupyterlab_gpu
├── Dockerfile
├── login.html
├── on_startup.sh
├── packages.txt
├── requirements.txt
└── start_server.sh
└── vscode_gpu
├── Dockerfile
├── on_startup.sh
├── packages.txt
├── requirements.txt
├── root
├── etc
│ └── s6-overlay
│ │ └── s6-rc.d
│ │ ├── init-config-end
│ │ └── dependencies.d
│ │ │ └── init-openvscode-server
│ │ ├── init-openvscode-server
│ │ ├── dependencies.d
│ │ │ └── init-config
│ │ ├── run
│ │ ├── type
│ │ └── up
│ │ ├── svc-openvscode-server
│ │ ├── dependencies.d
│ │ │ └── init-services
│ │ ├── notification-fd
│ │ ├── run
│ │ └── type
│ │ └── user
│ │ └── contents.d
│ │ ├── init-openvscode-server
│ │ └── svc-openvscode-server
└── usr
│ └── local
│ └── bin
│ └── install-extension
└── start_server.sh
/.github/workflows/sync_app_with_spaces.yml:
--------------------------------------------------------------------------------
1 | name: Sync app with Hugging Face Hub
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | paths:
8 | - .github/workflows/sync_app_with_spaces.yml
9 | - app/**
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: Sync with Hugging Face
16 | uses: nateraw/huggingface-sync-action@v0.0.5
17 | with:
18 | github_repo_id: nateraw/spaces-docker-templates
19 | huggingface_repo_id: DockerTemplates/docker-examples
20 | repo_type: space
21 | space_sdk: gradio
22 | subdirectory: app
23 | hf_token: ${{ secrets.HF_TOKEN }}
24 |
--------------------------------------------------------------------------------
/.github/workflows/sync_jupyterlab_gpu_with_spaces.yml:
--------------------------------------------------------------------------------
1 | name: Sync jupyterlab_gpu with Hugging Face Hub
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | paths:
8 | - .github/workflows/sync_jupyterlab_gpu_with_spaces.yml
9 | - jupyterlab_gpu/**
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: Sync with Hugging Face
16 | uses: nateraw/huggingface-sync-action@v0.0.5
17 | with:
18 | github_repo_id: nateraw/spaces-docker-templates
19 | huggingface_repo_id: DockerTemplates/jupyterlab
20 | repo_type: space
21 | space_sdk: docker
22 | subdirectory: jupyterlab_gpu
23 | hf_token: ${{ secrets.HF_TOKEN }}
--------------------------------------------------------------------------------
/.github/workflows/sync_vscode_gpu_with_spaces.yml:
--------------------------------------------------------------------------------
1 | name: Sync vscode_gpu with Hugging Face Hub
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | paths:
8 | - .github/workflows/sync_vscode_gpu_with_spaces.yml
9 | - vscode_gpu/**
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: Sync with Hugging Face
16 | uses: nateraw/huggingface-sync-action@v0.0.5
17 | with:
18 | github_repo_id: nateraw/spaces-docker-templates
19 | huggingface_repo_id: DockerTemplates/vscode
20 | repo_type: space
21 | space_sdk: docker
22 | subdirectory: vscode_gpu
23 | hf_token: ${{ secrets.HF_TOKEN }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
131 | .DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
10 |
11 |

12 |
You can duplicate this Space to run it private.
13 |
14 |
15 | 
16 |
17 |
18 |
Token is huggingface
19 |
20 | {% if login_available %}
21 | {# login_available means password-login is allowed. Show the form. #}
22 |
44 | {% else %}
45 |
{% trans %}No login available, you shouldn't be seeing this page.{% endtrans %}
46 | {% endif %}
47 | {% if message %}
48 |
49 | {% for key in message %}
50 |
51 | {{message[key]}}
52 |
53 | {% endfor %}
54 |
55 | {% endif %}
56 | {% if token_available %}
57 | {% block token_message %}
58 |
59 | {% endblock token_message %}
60 | {% endif %}
61 |
62 |
63 | {% endblock %}
64 |
65 |
66 | {% block script %}
67 | {% endblock %}
--------------------------------------------------------------------------------
/jupyterlab_gpu/on_startup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Write some commands here that will run on root user before startup.
3 | # For example, to clone transformers and install it in dev mode:
4 | # git clone https://github.com/huggingface/transformers.git
5 | # cd transformers && pip install -e ".[dev]"
--------------------------------------------------------------------------------
/jupyterlab_gpu/packages.txt:
--------------------------------------------------------------------------------
1 | tree
--------------------------------------------------------------------------------
/jupyterlab_gpu/requirements.txt:
--------------------------------------------------------------------------------
1 | jupyterlab==3.6.1
2 | jupyter-server==2.3.0
3 | tornado==6.2
4 |
--------------------------------------------------------------------------------
/jupyterlab_gpu/start_server.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | JUPYTER_TOKEN="${JUPYTER_TOKEN:=huggingface}"
3 |
4 | echo "Starting Jupyter Lab with token $JUPYTER_TOKEN"
5 |
6 | jupyter-lab \
7 | --ip 0.0.0.0 \
8 | --port 7860 \
9 | --no-browser \
10 | --allow-root \
11 | --ServerApp.token="$JUPYTER_TOKEN" \
12 | --ServerApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" \
13 | --ServerApp.cookie_options="{'SameSite': 'None', 'Secure': True}" \
14 | --ServerApp.disable_check_xsrf=True \
15 | --LabApp.news_url=None \
16 | --LabApp.check_for_updates_class="jupyterlab.NeverCheckForUpdate"
--------------------------------------------------------------------------------
/vscode_gpu/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM nvidia/cuda:11.3.1-base-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 \
10 | curl \
11 | ca-certificates \
12 | sudo \
13 | git \
14 | git-lfs \
15 | zip \
16 | unzip \
17 | htop \
18 | bzip2 \
19 | libx11-6 \
20 | build-essential \
21 | libsndfile-dev \
22 | software-properties-common \
23 | && rm -rf /var/lib/apt/lists/*
24 |
25 | ARG BUILD_DATE
26 | ARG VERSION
27 | ARG CODE_RELEASE
28 | RUN \
29 | echo "**** install openvscode-server runtime dependencies ****" && \
30 | apt-get update && \
31 | apt-get install -y \
32 | jq \
33 | libatomic1 \
34 | nano \
35 | net-tools \
36 | netcat && \
37 | echo "**** install openvscode-server ****" && \
38 | if [ -z ${CODE_RELEASE+x} ]; then \
39 | CODE_RELEASE=$(curl -sX GET "https://api.github.com/repos/gitpod-io/openvscode-server/releases/latest" \
40 | | awk '/tag_name/{print $4;exit}' FS='[""]' \
41 | | sed 's|^openvscode-server-v||'); \
42 | fi && \
43 | mkdir -p /app/openvscode-server && \
44 | curl -o \
45 | /tmp/openvscode-server.tar.gz -L \
46 | "https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-v${CODE_RELEASE}/openvscode-server-v${CODE_RELEASE}-linux-x64.tar.gz" && \
47 | tar xf \
48 | /tmp/openvscode-server.tar.gz -C \
49 | /app/openvscode-server/ --strip-components=1 && \
50 | echo "**** clean up ****" && \
51 | apt-get clean && \
52 | rm -rf \
53 | /tmp/* \
54 | /var/lib/apt/lists/* \
55 | /var/tmp/*
56 | COPY root/ /
57 |
58 | RUN add-apt-repository ppa:flexiondotorg/nvtop && \
59 | apt-get upgrade -y && \
60 | apt-get install -y --no-install-recommends nvtop
61 |
62 | RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
63 | apt-get install -y nodejs && \
64 | npm install -g configurable-http-proxy
65 |
66 | # Create a working directory
67 | WORKDIR /app
68 |
69 | # Create a non-root user and switch to it
70 | RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
71 | && chown -R user:user /app
72 | RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
73 | USER user
74 |
75 | # All users can use /home/user as their home directory
76 | ENV HOME=/home/user
77 | RUN mkdir $HOME/.cache $HOME/.config \
78 | && chmod -R 777 $HOME
79 |
80 | # Set up the Conda environment
81 | ENV CONDA_AUTO_UPDATE_CONDA=false \
82 | PATH=$HOME/miniconda/bin:$PATH
83 | RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \
84 | && chmod +x ~/miniconda.sh \
85 | && ~/miniconda.sh -b -p ~/miniconda \
86 | && rm ~/miniconda.sh \
87 | && conda clean -ya
88 |
89 | WORKDIR $HOME/app
90 |
91 | #######################################
92 | # Start root user section
93 | #######################################
94 |
95 | USER root
96 |
97 | # User Debian packages
98 | ## Security warning : Potential user code executed as root (build time)
99 | RUN --mount=target=/root/packages.txt,source=packages.txt \
100 | apt-get update && \
101 | xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
102 | && rm -rf /var/lib/apt/lists/*
103 |
104 | RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
105 | bash /root/on_startup.sh
106 |
107 | #######################################
108 | # End root user section
109 | #######################################
110 |
111 | USER user
112 |
113 | # Python packages
114 | RUN --mount=target=requirements.txt,source=requirements.txt \
115 | pip install --no-cache-dir --upgrade -r requirements.txt
116 |
117 | # Copy the current directory contents into the container at $HOME/app setting the owner to the user
118 | COPY --chown=user . $HOME/app
119 |
120 | RUN chmod +x start_server.sh
121 |
122 | ENV PYTHONUNBUFFERED=1 \
123 | GRADIO_ALLOW_FLAGGING=never \
124 | GRADIO_NUM_PORTS=1 \
125 | GRADIO_SERVER_NAME=0.0.0.0 \
126 | GRADIO_THEME=huggingface \
127 | SYSTEM=spaces \
128 | SHELL=/bin/bash
129 |
130 | EXPOSE 7860 3000
131 |
132 | CMD ["./start_server.sh"]
133 |
--------------------------------------------------------------------------------
/vscode_gpu/on_startup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Write some commands here that will run on root user before startup.
3 | # For example, to clone transformers and install it in dev mode:
4 | # git clone https://github.com/huggingface/transformers.git
5 | # cd transformers && pip install -e ".[dev]"
--------------------------------------------------------------------------------
/vscode_gpu/packages.txt:
--------------------------------------------------------------------------------
1 | tree
--------------------------------------------------------------------------------
/vscode_gpu/requirements.txt:
--------------------------------------------------------------------------------
1 | # jupyterlab
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-openvscode-server:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nateraw/spaces-docker-templates/2c890138fdd8d2ea808f252ecbaff8dee6a86405/vscode_gpu/root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-openvscode-server
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/init-openvscode-server/dependencies.d/init-config:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nateraw/spaces-docker-templates/2c890138fdd8d2ea808f252ecbaff8dee6a86405/vscode_gpu/root/etc/s6-overlay/s6-rc.d/init-openvscode-server/dependencies.d/init-config
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/init-openvscode-server/run:
--------------------------------------------------------------------------------
1 | #!/usr/bin/with-contenv bash
2 |
3 | mkdir -p /config/{workspace,.ssh}
4 |
5 | if [ -n "${SUDO_PASSWORD}" ] || [ -n "${SUDO_PASSWORD_HASH}" ]; then
6 | echo "setting up sudo access"
7 | if ! grep -q 'abc' /etc/sudoers; then
8 | echo "adding abc to sudoers"
9 | echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
10 | fi
11 | if [ -n "${SUDO_PASSWORD_HASH}" ]; then
12 | echo "setting sudo password using sudo password hash"
13 | sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
14 | else
15 | echo "setting sudo password using SUDO_PASSWORD env var"
16 | echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
17 | fi
18 | fi
19 |
20 | [[ ! -f /config/.bashrc ]] && \
21 | cp /root/.bashrc /config/.bashrc
22 | [[ ! -f /config/.profile ]] && \
23 | cp /root/.profile /config/.profile
24 |
25 | # fix permissions (ignore contents of /config/workspace)
26 | echo "setting permissions::config"
27 | find /config -path /config/workspace -prune -o -exec chown abc:abc {} +
28 | chown abc:abc /config/workspace
29 | echo "setting permissions::app"
30 | chown -R abc:abc /app/openvscode-server
31 |
32 | chmod 700 /config/.ssh
33 | if [ -n "$(ls -A /config/.ssh)" ]; then
34 | chmod 600 /config/.ssh/*
35 | fi
36 |
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/init-openvscode-server/type:
--------------------------------------------------------------------------------
1 | oneshot
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/init-openvscode-server/up:
--------------------------------------------------------------------------------
1 | /etc/s6-overlay/s6-rc.d/init-openvscode-server/run
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/svc-openvscode-server/dependencies.d/init-services:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nateraw/spaces-docker-templates/2c890138fdd8d2ea808f252ecbaff8dee6a86405/vscode_gpu/root/etc/s6-overlay/s6-rc.d/svc-openvscode-server/dependencies.d/init-services
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/svc-openvscode-server/notification-fd:
--------------------------------------------------------------------------------
1 | 3
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/svc-openvscode-server/run:
--------------------------------------------------------------------------------
1 | #!/usr/bin/with-contenv bash
2 |
3 | if [ -n "$CONNECTION_SECRET" ]; then
4 | CODE_ARGS="${CODE_ARGS} --connection-secret ${CONNECTION_SECRET}"
5 | echo "Using connection secret from ${CONNECTION_SECRET}"
6 | elif [ -n "$CONNECTION_TOKEN" ]; then
7 | CODE_ARGS="${CODE_ARGS} --connection-token ${CONNECTION_TOKEN}"
8 | echo "Using connection token ${CONNECTION_TOKEN}"
9 | else
10 | CODE_ARGS="${CODE_ARGS} --without-connection-token"
11 | echo "**** No connection token is set ****"
12 | fi
13 |
14 | exec \
15 | s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z 127.0.0.1 3000" \
16 | cd /app/openvscode-server s6-setuidgid abc \
17 | /app/openvscode-server/bin/openvscode-server \
18 | --host 0.0.0.0 \
19 | --port 3000 \
20 | --disable-telemetry \
21 | ${CODE_ARGS}
22 |
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/svc-openvscode-server/type:
--------------------------------------------------------------------------------
1 | longrun
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-openvscode-server:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nateraw/spaces-docker-templates/2c890138fdd8d2ea808f252ecbaff8dee6a86405/vscode_gpu/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-openvscode-server
--------------------------------------------------------------------------------
/vscode_gpu/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-openvscode-server:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nateraw/spaces-docker-templates/2c890138fdd8d2ea808f252ecbaff8dee6a86405/vscode_gpu/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-openvscode-server
--------------------------------------------------------------------------------
/vscode_gpu/root/usr/local/bin/install-extension:
--------------------------------------------------------------------------------
1 | #!/usr/bin/with-contenv bash
2 | # shellcheck shell=bash
3 |
4 | _install=(/app/openvscode-server/bin/openvscode-server "--install-extension")
5 |
6 | if [ "$(whoami)" == "abc" ]; then
7 | "${_install[@]}" "$@"
8 | else
9 | s6-setuidgid abc "${_install[@]}" "$@"
10 | fi
11 |
--------------------------------------------------------------------------------
/vscode_gpu/start_server.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "Starting VSCode Server..."
4 |
5 | exec /app/openvscode-server/bin/openvscode-server --host 0.0.0.0 --port 7860 --without-connection-token \"${@}\" --
6 |
--------------------------------------------------------------------------------