Example #1
0
                                    schema=schema,
                                    nullValue="NA")

df = telco_data_raw.toPandas()

# Get the various Model CRN details
HOST = os.getenv("CDSW_API_URL").split(":")[0] + "://" + os.getenv(
    "CDSW_DOMAIN")
USERNAME = os.getenv("CDSW_PROJECT_URL").split("/")[6]
API_KEY = os.getenv("CDSW_API_KEY")
PROJECT_NAME = os.getenv("CDSW_PROJECT")

cml = CMLBootstrap(HOST, USERNAME, API_KEY, PROJECT_NAME)

# Get newly deployed churn model details using cmlbootstrapAPI
models = cml.get_models({})
churn_model_details = [
    model for model in models
    if model["name"] == "Churn Model API Endpoint" and model["creator"]
    ["username"] == USERNAME and model["project"]["slug"] == PROJECT_NAME
][0]
latest_model = cml.get_model({
    "id": churn_model_details["id"],
    "latestModelDeployment": True,
    "latestModelBuild": True,
})

Model_CRN = latest_model["crn"]
Deployment_CRN = latest_model["latestModelDeployment"]["crn"]
model_endpoint = (HOST.split("//")[0] + "//modelservice." +
                  HOST.split("//")[1] + "/model")
Example #2
0
    6]  # args.username  # "vdibia"
API_KEY = "uuc48l0gm0r3n2mib27voxazoos65em0"
PROJECT_NAME = os.getenv("CDSW_PROJECT")

# Instantiate API Wrapper
cml = CMLBootstrap(HOST, USERNAME, API_KEY, PROJECT_NAME)

#Retrieve model access keys for models that are compared

#Champion can be either hardcoded or can be the most recent model from the day it was deployed
#mvav17o0lwb9oogg3jlh8g7wqaw99e6w
champion_ak = "mvav17o0lwb9oogg3jlh8g7wqaw99e6w"

#Challenger is the most recent model deployed today
project_id = cml.get_project({})['id']  #get project ID
deployed_models_df = pd.DataFrame(cml.get_models({}))
challenger_ak = deployed_models_df[deployed_models_df['projectId'] == project_id]\
    .sort_values("createdAt", ascending=False)['accessKey'].iloc[0]


def route_request(args):

    coin = random.randint(0, 1)

    #TODO: make this more coincise. Something messing up json
    #TODO: add more metadata about model chosen
    if coin == 0:
        r = requests.post(
            'http://modelservice.ml-2f4cffbb-91e.demo-aws.ylcu-atmi.cloudera.site/model',
            data=
            '{"accessKey":"mvav17o0lwb9oogg3jlh8g7wqaw99e6w","request":{"recency":"2","history":"3","used_discount":"0","used_bogo":"1","is_referral":"1","channel_Phone":"1","channel_Web":"1","offer_Discount":"0","offer_No Offer":"1"}}',