-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-notebook
More file actions
executable file
·79 lines (59 loc) · 2.29 KB
/
create-notebook
File metadata and controls
executable file
·79 lines (59 loc) · 2.29 KB
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
#!/bin/bash
export AWS_DEFAULT_OUTPUT=json
ACCOUNT=$(aws sts get-caller-identity | jq -r .Account)
REGION=$(aws configure get region)
# Assume role and bucket already exists
ROLE=$(aws iam list-roles | jq -r '.Roles | .[] | .Arn' | grep service-role | grep SageMaker)
NOTEBOOK_NAME=rps
BUCKET="ac3-sumerian-rps-sagemaker"
aws sagemaker create-notebook-instance \
--notebook-instance-name ${NOTEBOOK_NAME} \
--instance-type ml.p2.xlarge \
--role-arn "${ROLE}" \
| jq .
echo -n Waiting for notebook to start
while [ $(aws sagemaker describe-notebook-instance --notebook-instance-name ${NOTEBOOK_NAME} | jq -r .NotebookInstanceStatus) != "InService" ]; do
echo -n .
sleep 1
done
echo Done
URL=$(aws sagemaker create-presigned-notebook-instance-url \
--notebook-instance-name ${NOTEBOOK_NAME} \
| jq -r .AuthorizedUrl
)
BASEURL=${URL%%?authToken*}
JAR=$(mktemp /tmp/cookie-jar.XXXXXX)
DATA=$(mktemp /tmp/data.XXXXXX)
CURL_ARGS="--silent --cookie $JAR --cookie-jar $JAR"
# Log in
curl ${CURL_ARGS} --location "${URL}" --silent > /dev/null
echo 'Uploading...'
echo '{"content": '"$(cat notebook.ipynb)"', "format": "json", "type": "notebook"}' >| $DATA
curl ${CURL_ARGS} -X PUT "${BASEURL}/api/contents/notebook.ipynb" --data @$DATA > /dev/null
echo "Visit ${BASEURL} and run the notebook then press enter"
echo
echo "Waiting..."
read
echo "Downloading..."
# List contents
curl ${CURL_ARGS} "${BASEURL}/api/contents" | jq .
curl ${CURL_ARGS} "${BASEURL}/api/contents/notebook.ipynb" | jq -r .content >| notebook-new.ipynb
jupyter nbconvert --to html notebook-new.ipynb --output notebook.html
## Convert the model to something useable
curl ${CURL_ARGS} "${BASEURL}/api/contents/rps-keras-final.hdf5" | jq -r .content | base64 -d >| rps-keras-final.hdf5
tensorflowjs_converter --input_format keras model/keras/rps-keras-final.hdf5 public/tsmodel
echo "Done".
echo "Nuking everything..."
rm ${JAR} ${DATA}
aws sagemaker stop-notebook-instance \
--notebook-instance-name ${NOTEBOOK_NAME} \
| jq .
echo -n Waiting for notebook to stop
while [ $(aws sagemaker describe-notebook-instance --notebook-instance-name ${NOTEBOOK_NAME} | jq -r .NotebookInstanceStatus) != "Stopped" ]; do
echo -n .
sleep 1
done
echo Done
aws sagemaker delete-notebook-instance \
--notebook-instance-name ${NOTEBOOK_NAME} \
| jq .