Skip to content

Instantly share code, notes, and snippets.

View ismaelc's full-sized avatar

Chris Ismael ismaelc

View GitHub Profile
@ismaelc
ismaelc / run_notebook.py
Created March 5, 2023 00:40
Send bootstrap script to pull ipynb via FrameworkProcessor
from sagemaker.processing import ProcessingInput, ProcessingOutput
script_processor.framework_entrypoint_command = ['python3']
script_processor.run(
job_name=job_name,
code=f"{base_url}/processing_job/code/run_notebook-{random_string}.py",
source_dir=f"{base_url}/processing_job/code",
inputs=[
ProcessingInput(
source=s3_notebook_path,
# Stop the notebook execution
raise SystemExit('Notebook end')
# Send this notebook to the runner
notebook = '<your notebook>.ipynb'
src = '<your S3 bucket/folder>'
notebook_uri = f'{src}{notebook}'
!aws s3 cp {notebook} {notebook_uri}
payload = '{"input_path": "NOTEBOOK_URI", "image": "<image name>"}'.replace('NOTEBOOK_URI', notebook_uri)
print(payload)
@ismaelc
ismaelc / sm-run-notebook.sh
Created November 28, 2021 01:12
sagemaker-run-notebook example
$ aws lambda invoke --function-name RunNotebook --payload '{"input_path": "s3://mybucket/mynotebook.ipynb", "image": "notebook-runner", "parameters": {"p": 0.75}}' result.json
from sagemaker.sklearn.processing import SKLearnProcessor
from sagemaker.processing import ProcessingInput, ProcessingOutput
sklearn_processor = SKLearnProcessor(framework_version='0.20.0',
role=role,
instance_type='ml.m5.xlarge',
instance_count=1)
sklearn_processor.run(code='preprocessing.py',
inputs=[ProcessingInput(
import json
import tempfile
import subprocess
import ipywidgets as widgets
from ipywidgets import Button, Layout, HBox, VBox, Dropdown, HTML
from IPython.display import display, clear_output
BUCKET = "dsml-chrisi-bucket"
FOLDER = "quickshare"
TMPDIR = tempfile.gettempdir()
let range = context.workbook.getSelectedRange()
range.load("values");
await context.sync();
let data = range.values
function trainModel(data) {
classifier = new Classifier({
nGramMin: 1,
nGramMax: 3,
});
for (let key in data) {
classifier.train(data[key], key);
}
}
/*
* Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
* See LICENSE in the project root for license information.
*/
// images references in the manifest
import "../../assets/icon-16.png";
import "../../assets/icon-32.png";
import "../../assets/icon-80.png";
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. -->
<!-- This file shows how to design a first-run page that provides a welcome screen to the user about the features of the add-in. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
let range = resolveRange(selectedRange.address, usedRange.address)
range = book.worksheets
.getActiveWorksheet()
.getRange(range);
range.load("values");
await context.sync();
processedData = processData(range.values);