コード例 #1
0
ファイル: credentials.py プロジェクト: chrinide/a2ml
    def load(self):
        content = {}
        if hasattr(self.ctx, 'credentials'):
            content = self.ctx.credentials
        elif 'AZURE_CREDENTIALS' in os.environ:
            content = os.environ.get('AZURE_CREDENTIALS', None)
            content = json.loads(content) if content else {}
        else:
            #look for service principal credentials
            if self._credentials_file_exist():
                with open(self.creds_file, 'r') as file:
                    content = json.loads(file.read())
            else:
                content = self._load_azure_cred_file()

                if not content.get('subscription_id'
                                   ) and not self.ctx.config.get('use_server'):
                    from azureml.core.authentication import InteractiveLoginAuthentication
                    #fallback to force browser login for token
                    interactive_auth = InteractiveLoginAuthentication(
                        force=True)
                    interactive_auth.get_authentication_header()

                    content = self._load_azure_cred_file()

        self.subscription_id = content.get('subscription_id')
        self.directory_tenant_id = content.get('directory_tenant_id')
        self.application_client_id = content.get('application_client_id')
        self.client_secret = content.get('client_secret')

        return self
コード例 #2
0
def query_confidence(query):

    # Get a token to authenticate to the compute instance from remote
    interactive_auth = InteractiveLoginAuthentication()
    auth_header = interactive_auth.get_authentication_header()

    headers = auth_header
    # Add content type header
    headers.update({'Content-Type': 'application/json'})

    # Sample data to send to the service

    test_sample = bytes(query, encoding='utf8')

    # Replace with the URL for your compute instance, as determined from the previous section
    service_url = "https://fact-check-8890.eastus.instances.azureml.net/score"

    # for a compute instance, the url would be https://vm-name-6789.northcentralus.instances.azureml.net/score
    resp = requests.post(service_url, test_sample, headers=headers)
    #print("prediction:", resp.text)

    response = [float(i) for i in list(((resp.text[2:])[:-2]).split(','))]

    return response
# COMMAND ----------

# MAGIC %run ./99-Shared-Functions-and-Settings

# COMMAND ----------

# MAGIC %md
# MAGIC #### Login to Azure Machine Learning Workspace

# COMMAND ----------

from azureml.core import Workspace, Experiment, Run
from azureml.core.authentication import InteractiveLoginAuthentication

up = InteractiveLoginAuthentication()
up.get_authentication_header()

ws = Workspace(**AZURE_ML_CONF, auth=up)

# COMMAND ----------

from pyspark.ml import Pipeline
from pyspark.sql.functions import *
from pyspark.ml.feature import StringIndexer, OneHotEncoderEstimator, VectorAssembler, StandardScaler
from pyspark.ml.regression import RandomForestRegressor, LinearRegression, GBTRegressor
from pyspark.ml.evaluation import RegressionEvaluator
import matplotlib.pyplot as plt
import shutil
import os

# COMMAND ----------
コード例 #4
0
published_pipeline = succ_pipeline.publish(
    name="succ_Planning_Reg_Sevice_Model3",
    description="Trains model and Creates the Service",
    version="1.0")
rest_endpoint = published_pipeline.endpoint
print(rest_endpoint)

from azureml.core.authentication import InteractiveLoginAuthentication

interactive_auth = InteractiveLoginAuthentication()
auth_header = interactive_auth.get_authentication_header()

import requests

experiment_name = 'RegExp3'

response = requests.post(rest_endpoint,
                         headers=auth_header,
                         json={
                             "ExperimentName": experiment_name,
                             "ParameterAssignments": {
                                 "data": default
                             }
                         })
run_id = response.json()["Id"]
run_id