-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiabeticPrediction.py
More file actions
62 lines (49 loc) · 2.58 KB
/
Copy pathDiabeticPrediction.py
File metadata and controls
62 lines (49 loc) · 2.58 KB
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
import urllib.request
import json
import os
import ssl
print("Hi, We are going to predict the severe effects of Diabetic patient based on his past health history")
print("Please go through the MarK down readme files for the Dataset & ProjectDetails")
print(" ****** ")
def allowSelfSignedHttps(allowed):
# bypass the server certificate verification on client side
if allowed and not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None):
ssl._create_default_https_context = ssl._create_unverified_context
allowSelfSignedHttps(True) # this line is needed if you use self-signed certificate in your scoring service.
# Request data goes here
data = {
"Inputs": {
"input1":
[
{
'preg': input("Number of times pregnant :"),
'plas': input("Plasma glucose concentration a 2 hours in an oral glucose tolerance test, Usual-Range 50-190 :"),
'pres': input("Diastolic blood pressure in (mm Hg), Usaual-Range 25-100 :"),
'skin': input("Triceps skin fold thickness (mm) Usual-Range 5-70:"),
'mass': input("Body mass index (weight in kg/(height in m)^2) Usual-Range 18-40 :"),
'age': input("Age :"),
'class': "1",
},
],
},
"GlobalParameters": {
}
}
body = str.encode(json.dumps(data))
url = 'http://0d2a3cc9-e80a-403d-a8bf-5ebdd0b89413.southcentralus.azurecontainer.io/score'
api_key = 'v835s6n4VBAn2D883NNXIkiJRGE7GpiM' # Replace this with the API key for the web service
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}
req = urllib.request.Request(url, body, headers)
try:
response = urllib.request.urlopen(req)
result = response.read()
json_result = json.loads(result)
output = json_result["Results"]["WebServiceOutput0"][0]
print('The Diabetic Prediction of Patient Aged : {} with a diabetic Prediction: {} where 1.0 means Diabetic else not with a Probability: {:.2f}'.format(output["age"],
output["Scored Labels"],
output["Scored Probabilities"]))
except urllib.error.HTTPError as error:
print("The request failed with status code: " + str(error.code))
# Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
print(error.info())
print(json.loads(error.read().decode("utf8", 'ignore')))