From 2c56b19ccdee4b1512bcdea89d397c2005fc48c8 Mon Sep 17 00:00:00 2001 From: Qing Lan Date: Thu, 17 Sep 2020 18:24:34 -0700 Subject: [PATCH] add runnable notebook Change-Id: If2f5a649f47f364400e5a4a49516afeb20a51c7f --- .github/workflows/docs.yml | 5 ++++- apt.txt | 1 + jupyter/README.md | 2 ++ postBuild | 5 +++++ tools/scripts/Dockerfile.gpu | 6 ------ tools/scripts/add_online_runner.py | 13 +++++++++++++ tools/scripts/create_with_nvidia_docker.sh | 16 ---------------- 7 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 apt.txt create mode 100644 postBuild delete mode 100644 tools/scripts/Dockerfile.gpu create mode 100644 tools/scripts/add_online_runner.py delete mode 100644 tools/scripts/create_with_nvidia_docker.sh diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 025e491a5bc..c88469ae436 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -30,8 +30,11 @@ jobs: - name: run Notebooks run: | cd djl_tmp/jupyter - rm -rf d2l-java bash test_notebook.sh + - name: add mybinder link + run: | + cd djl_tmp + python3 tools/scripts/add_online_runner.py - name: build docs run: | cd djl_tmp/docs diff --git a/apt.txt b/apt.txt new file mode 100644 index 00000000000..7083f85c374 --- /dev/null +++ b/apt.txt @@ -0,0 +1 @@ +openjdk-11-jdk diff --git a/jupyter/README.md b/jupyter/README.md index 416408cce12..b68f384113b 100644 --- a/jupyter/README.md +++ b/jupyter/README.md @@ -14,6 +14,8 @@ This folder contains tutorials that illustrate how to accomplish basic AI tasks - [Transfer learning example](transfer_learning_on_cifar10.ipynb) - [Question answering example](BERTQA.ipynb) +You can run our notebook online: [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/awslabs/djl/master?filepath=jupyter) + ## Setup ### JDK 11 (not jre) diff --git a/postBuild b/postBuild new file mode 100644 index 00000000000..f6102a6bf5f --- /dev/null +++ b/postBuild @@ -0,0 +1,5 @@ +git clone https://github.com/frankfliu/IJava.git +cd IJava/ +./gradlew installKernel +cd .. +rm -rf Ijava/ ~/.gradle diff --git a/tools/scripts/Dockerfile.gpu b/tools/scripts/Dockerfile.gpu deleted file mode 100644 index 2a37189d1ca..00000000000 --- a/tools/scripts/Dockerfile.gpu +++ /dev/null @@ -1,6 +0,0 @@ -FROM nvidia/cuda:10.1-runtime-ubuntu16.04 -RUN apt-get update || true -RUN apt-get install -y wget unzip openjdk-8-jdk-headless -RUN apt-get install -y python3-pip -RUN pip3 install mxnet-cu101mkl -ENV export LD_LIBRARY_PATH=/usr/local/lib/python3.5/dist-packages/mxnet/:$LD_LIBRARY_PATH diff --git a/tools/scripts/add_online_runner.py b/tools/scripts/add_online_runner.py new file mode 100644 index 00000000000..fa04a21ba28 --- /dev/null +++ b/tools/scripts/add_online_runner.py @@ -0,0 +1,13 @@ +from pathlib import Path +import glob, json + +constructor = {"cell_type": "markdown", "metadata": {}} +prefix = "Run this notebook online:[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/awslabs/djl/master?filepath=" + +for file in Path('.').glob('**/*.ipynb'): + with open(file, mode= "r", encoding= "utf-8") as f: + data = json.loads(f.read()) + with open(file, 'w') as writer: + constructor["source"] = [prefix + str(file) + ")"] + data["cells"].insert(0, constructor) + writer.write(json.dumps(data)) diff --git a/tools/scripts/create_with_nvidia_docker.sh b/tools/scripts/create_with_nvidia_docker.sh deleted file mode 100644 index c55efa87ba0..00000000000 --- a/tools/scripts/create_with_nvidia_docker.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# Install Docker -apt-get update -apt-get install -y apt-transport-https ca-certificates curl software-properties-common -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - -add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -apt-get update -apt-get install docker-ce -# Install NVIDIA docker -curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \ -apt-key add distribution=$(. /etc/os-release;echo $ID$VERSION_ID) -curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \ -tee /etc/apt/sources.list.d/nvidia-docker.list -apt-get update -apt-get install -y nvidia-docker2 -pkill -SIGHUP dockerd