{ "cells": [ { "cell_type": "markdown", "id": "f5033a14", "metadata": {}, "source": [ "# **Amazon Lookout for Equipment** - Time series annotation with LabelStudio\n", "\n", "*Part 1 - Initialization*" ] }, { "cell_type": "markdown", "id": "7df7595e", "metadata": {}, "source": [ "## Initialization\n", "---\n", "### Imports" ] }, { "cell_type": "code", "execution_count": null, "id": "37693c57", "metadata": {}, "outputs": [], "source": [ "import boto3\n", "from json import load" ] }, { "cell_type": "markdown", "id": "309916e3", "metadata": {}, "source": [ "### Helper functions" ] }, { "cell_type": "code", "execution_count": null, "id": "9939903a", "metadata": {}, "outputs": [], "source": [ "def get_notebook_name():\n", " log_path = '/opt/ml/metadata/resource-metadata.json'\n", " with open(log_path, 'r') as logs:\n", " _logs = load(logs)\n", " \n", " return _logs['ResourceName']" ] }, { "cell_type": "markdown", "id": "a41a32fb", "metadata": {}, "source": [ "### Parameters\n", "Run the following cell to collect the parameters needed to run the LabelStudio container:" ] }, { "cell_type": "code", "execution_count": null, "id": "ccdde1f8", "metadata": {}, "outputs": [], "source": [ "notebook_name = get_notebook_name()\n", "session = boto3.session.Session()\n", "current_region = session.region_name" ] }, { "cell_type": "markdown", "id": "5f2c3b14", "metadata": {}, "source": [ "### Setup authentication\n", "You will need to authenticate yourself against LabelStudio. Update the following cell before running it to setup your `user`, `password` and `token`:" ] }, { "cell_type": "code", "execution_count": null, "id": "03a876fb", "metadata": {}, "outputs": [], "source": [ "# Must follow a valid email address format:\n", "username = 'username@domain.com'\n", "\n", "# Fill in a password for your LabelStudio user:\n", "password = 'password'\n", "\n", "# You can uncomment the following lines to generate a unique token:\n", "# from binascii import hexlify\n", "# from os import urandom\n", "# token = hexlify(urandom(20)).decode()\n", "\n", "# Or you can manually set one:\n", "token = 'LabelStudioAPIToken'\n", "print(token)" ] }, { "cell_type": "markdown", "id": "429ae0e1", "metadata": {}, "source": [ "Let's store these variables in the Jupyter environment so that we can use them in the next notebook:" ] }, { "cell_type": "code", "execution_count": null, "id": "c13d72f1", "metadata": {}, "outputs": [], "source": [ "%store token\n", "%store notebook_name\n", "%store current_region" ] }, { "cell_type": "markdown", "id": "66e687a7", "metadata": {}, "source": [ "## Run LabelStudio\n", "---\n", "Run the following cell to create a shell script which will download a Docker image for LabelStudio and run it:" ] }, { "cell_type": "code", "execution_count": null, "id": "8fe4f29e", "metadata": {}, "outputs": [], "source": [ "with open('label-studio.sh', 'w') as f:\n", " f.write('#!/bin/bash\\n')\n", " f.write(f\"\"\"docker run \\\n", " -it \\\n", " -p 8080:8080 \\\n", " -v /home/ec2-user/SageMaker/label-studio-data:/label-studio/data \\\n", " heartexlabs/label-studio:latest label-studio start --username {username} --password {password} --user-token {token} \\\n", " --host https://{notebook_name}.notebook.{current_region}.sagemaker.aws/proxy/8080\"\"\")" ] }, { "cell_type": "markdown", "id": "eefce277", "metadata": {}, "source": [ "The following cell will run the script you just created and launch LabelStudio. Once you see the following message, you can cruise over the next notebook:\n", "\n", "```\n", "Django version 3.1.14, using settings 'core.settings.label_studio'\n", "Starting development server at http://0.0.0.0:8080/\n", "Quit the server with CONTROL-C.\n", "```\n", "\n", "The following cell will stay in a running state (note the `[*]` next to it) until you forcefully stop it (note that this will also stop LabelStudio):" ] }, { "cell_type": "code", "execution_count": null, "id": "727d0fd7", "metadata": {}, "outputs": [], "source": [ "!source ./label-studio.sh" ] }, { "cell_type": "markdown", "id": "c563b196", "metadata": {}, "source": [ "## Cleanup\n", "---\n", "If you want to stop LabelStudio, just click on the `Interrupt the kernel` button in this notebooks toolbar.\n", "\n", "If you don't want to keep your labeling projects with your ongoing label work, you can safely delete the `/home/ec2-user/SageMaker/label-studio-data` folder where all the label data is stored.\n", "\n", "**Do not delete** this folder if you want to continue your labeling work later, or isn't done processing the labeling job outputs." ] } ], "metadata": { "kernelspec": { "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.13" } }, "nbformat": 4, "nbformat_minor": 5 }