@@ -79,6 +79,7 @@ The workspace is the top-level resource for Azure Machine Learning, providing a
79
79
```python
80
80
import json
81
81
import mlflow
82
+ import urllib.request
82
83
from mlflow.deployments import get_deploy_client
83
84
```
84
85
@@ -339,6 +340,74 @@ So far, the endpoint is empty. There are no deployments on it. Let's create the
339
340
)
340
341
```
341
342
343
+ 1. Create a sample input to test the deployment
344
+
345
+ # [Azure CLI](#tab/cli)
346
+
347
+ __sample.yml__
348
+
349
+ ```yml
350
+ {
351
+ "input_data": {
352
+ "columns": [
353
+ "age",
354
+ "sex",
355
+ "cp",
356
+ "trestbps",
357
+ "chol",
358
+ "fbs",
359
+ "restecg",
360
+ "thalach",
361
+ "exang",
362
+ "oldpeak",
363
+ "slope",
364
+ "ca",
365
+ "thal"
366
+ ],
367
+ "data": [
368
+ [ 48, 0, 3, 130, 275, 0, 0, 139, 0, 0.2, 1, 0, "normal" ]
369
+ ]
370
+ }
371
+ }
372
+ ```
373
+
374
+ # [Python (Azure ML SDK)](#tab/sdk)
375
+
376
+ The following code samples 5 observations from the training dataset, removes the `target` column (as the model will predict it), and creates a request in the file `sample.json` that can be used with the model deployment.
377
+
378
+ ```python
379
+ samples = (
380
+ pd.read_csv("data/heart.csv")
381
+ .sample(n=5)
382
+ .drop(columns=["target"])
383
+ .reset_index(drop=True)
384
+ )
385
+
386
+ with open("sample.json", "w") as f:
387
+ f.write(
388
+ json.dumps(
389
+ {"input_data": json.loads(samples.to_json(orient="split", index=False))}
390
+ )
391
+ )
392
+ ```
393
+
394
+ # [Python (MLflow SDK)](#tab/mlflow)
395
+
396
+ The following code samples 5 observations from the training dataset, removes the `target` column (as the model will predict it), and creates a request.
397
+
398
+ ```python
399
+ samples = (
400
+ pd.read_csv("data/heart.csv")
401
+ .sample(n=5)
402
+ .drop(columns=["target"])
403
+ .reset_index(drop=True)
404
+ )
405
+
406
+ sample_request = json.dumps(
407
+ {"input_data": json.loads(samples.to_json(orient="split", index=False))}
408
+ )
409
+ ```
410
+
342
411
1. Test the deployment
343
412
344
413
# [Azure CLI](#tab/cli)
@@ -357,17 +426,31 @@ So far, the endpoint is empty. There are no deployments on it. Let's create the
357
426
```
358
427
359
428
# [Python (MLflow SDK)](#tab/mlflow)
429
+
430
+ Get the scoring URI:
431
+
432
+ ```python
433
+ scoring_uri = deployment_client.get_endpoint(endpoint=endpoint_name)["properties"]["scoringUri"]
434
+ ```
360
435
361
- Let's create the authentication header :
436
+ Let's create the headers :
362
437
363
438
```python
364
- authentication_header = f"'Authorization: Bearer {endpoint_secret_key}'"
439
+ headers = {
440
+ 'Content-Type':'application/json',
441
+ 'Authorization':('Bearer '+ endpoint_secret_key),
442
+ 'azureml-model-deployment': 'default'
443
+ }
365
444
```
366
445
367
446
Call the endpoint and its default deployment:
368
447
369
448
```python
370
-
449
+ req = urllib.request.Request(scoring_uri, sample_request, headers)
450
+ response = urllib.request.urlopen(req)
451
+
452
+ result = response.read()
453
+ print(result)
371
454
```
372
455
373
456
### Create a green deployment under the endpoint
0 commit comments