Skip to content

Instantly share code, notes, and snippets.

View aribornstein's full-sized avatar

PythicCoder aribornstein

View GitHub Profile
@aribornstein
aribornstein / eventhub_rest_authentication.py
Last active November 8, 2017 19:07
Python Eventhub Rest Authentication Example
import time
import urllib
import hmac
import hashlib
import base64
def get_auth_token(sb_name, eh_name, sas_name, sas_value):
"""
Returns an auth token dictionary for making calls to eventhub
REST API.
@aribornstein
aribornstein / FetchAzureBlobContainer.js
Created March 17, 2019 10:19
Fetch Azure Blob Container List JS
fetch("https://{namespace}.blob.core.windows.net/{containerName}/?restype=container&comp=list")
.then(response => response.text())
.then(str => new window.DOMParser().parseFromString(str, "text/xml"))
.then(xml => {
let blobList = Array.from(xml.querySelectorAll("Url")); //.getAttribute("Url");
blobList.forEach(async blobUrl => {
console.log(blobUrl);
});
@aribornstein
aribornstein / rgb2lab.js
Last active March 17, 2019 12:59
tensorflow.js RGB2LAB code example
//http://www.easyrgb.com/en/math.php
function tfRGB2LAB(rgb) {
let a_con = tf.pow(rgb.add(0.055).div(1.055), 2.4);
let b_con = rgb.div(12.92);
let rgb_2 = tf.where(rgb.greater(0.04045), a_con, b_con);
const [r, g, b] = rgb_2.split(3, 2);
let x = r
@aribornstein
aribornstein / OCR_from_file.py
Created April 10, 2019 19:24
Azure Cognitive Services OCR From File Example
import requests
# If you are using a Jupyter notebook, uncomment the following line.
#%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from PIL import Image
from io import BytesIO
# Replace <Subscription Key> with your valid subscription key.
subscription_key = ""
########### Python Form Recognizer Train #############
from requests import post as http_post
# Endpoint URL
base_url = r"<Endpoint>" + "/formrecognizer/v1.0-preview/custom"
source = r"<SAS URL>"
headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '<Subscription Key>',
from azureml.train.estimator import Estimator
script_params = {
'--data_folder': ds,
}
nlp_est = Estimator(source_directory='.',
script_params=script_params,
compute_target=cluster,
entry_script='train.py',
@aribornstein
aribornstein / LowPriorityInstances.py
Last active August 27, 2019 12:41
LowPriorityInstances
from azureml.core.compute import ComputeTarget, AmlCompute
from azureml.core.compute_target import ComputeTargetException
cluster_name = "cluster"
compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_D3_V2', # VM Size N series have GPU
vm_priority='lowpriority', # Cheap Computer
min_nodes=0, # Auto Scale Min Limit
max_nodes=5) #Auto Scale Max Limit
cluster = ComputeTarget.create(ws, cluster_name, compute_config)
cluster.wait_for_completion(show_output=True)
@aribornstein
aribornstein / aml_aciconfig.py
Created September 13, 2019 11:56
ACI Config
from azureml.core.webservice import AciWebservice
aciconfig = AciWebservice.deploy_configuration(cpu_cores=1,
memory_gb=1,
tags={"data": "text", "method" : "NLP Architcet ABSA"},
description='Predict ABSA with NLP Architect')
@aribornstein
aribornstein / aml_enviroment.py
Created September 13, 2019 12:00
Create Environment File for Azure ML
from azureml.core.conda_dependencies import CondaDependencies
pip = ["azureml-defaults", "azureml-monitoring", "git+https://github.com/NervanaSystems/nlp-architect.git@absa"]
myenv = CondaDependencies.create(pip_packages=pip)
with open("myenv.yml","w") as f:
f.write(myenv.serialize_to_string())
@aribornstein
aribornstein / aml_aci_env_vars.py
Created September 13, 2019 12:02
aml_aci_env
from azureml.core import Environment
deploy_env = Environment.from_conda_specification('absa_env', "myenv.yml")
deploy_env.environment_variables={'NLP_ARCHITECT_BE': 'CPU'}