-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.py
73 lines (67 loc) · 2.14 KB
/
endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import requests
import json
# URL for the web service, should be similar to:
# 'http://8530a665-66f3-49c8-a953-b82a2d312917.eastus.azurecontainer.io/score'
scoring_uri = 'http://983e252c-5659-4dbf-b531-498353447ba6.southcentralus.azurecontainer.io/score'
# If the service is authenticated, set the key or token
key = 'uTsCm5fhEuVtoyqAM6xWWr2PnfIm8tVc'
# Two sets of data to score, so we get two results back
data = {"data":
[
{
"age": 17,
"campaign": 1,
"cons.conf.idx": -46.2,
"cons.price.idx": 92.893,
"contact": "cellular",
"day_of_week": "mon",
"default": "no",
"duration": 971,
"education": "university.degree",
"emp.var.rate": -1.8,
"euribor3m": 1.299,
"housing": "yes",
"job": "blue-collar",
"loan": "yes",
"marital": "married",
"month": "may",
"nr.employed": 5099.1,
"pdays": 999,
"poutcome": "failure",
"previous": 1
},
{
"age": 87,
"campaign": 1,
"cons.conf.idx": -46.2,
"cons.price.idx": 92.893,
"contact": "cellular",
"day_of_week": "mon",
"default": "no",
"duration": 471,
"education": "university.degree",
"emp.var.rate": -1.8,
"euribor3m": 1.299,
"housing": "yes",
"job": "blue-collar",
"loan": "yes",
"marital": "married",
"month": "may",
"nr.employed": 5099.1,
"pdays": 999,
"poutcome": "failure",
"previous": 1
},
]
}
# Convert to JSON string
input_data = json.dumps(data)
with open("data.json", "w") as _f:
_f.write(input_data)
# Set the content type
headers = {'Content-Type': 'application/json'}
# If authentication is enabled, set the authorization header
headers['Authorization'] = f'Bearer {key}'
# Make the request and display the response
resp = requests.post(scoring_uri, input_data, headers=headers)
print(resp.json())