forked from udacity/nd0821-c3-starter-code
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpost_to_API.py
More file actions
41 lines (32 loc) · 1.08 KB
/
Copy pathpost_to_API.py
File metadata and controls
41 lines (32 loc) · 1.08 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
"""
Script to post to FastAPI instance for model inference
author: Laurent veyssier
Date: Dec. 18th 2022
"""
import requests
import json
#url = "enter heroku web app url here"
url = "https://udacity-fastapi-app.herokuapp.com/inference"
# explicit the sample to perform inference on
sample = { 'age':50,
'workclass':"Private",
'fnlgt':234721,
'education':"Doctorate",
'education_num':16,
'marital_status':"Separated",
'occupation':"Exec-managerial",
'relationship':"Not-in-family",
'race':"Black",
'sex':"Female",
'capital_gain':0,
'capital_loss':0,
'hours_per_week':50,
'native_country':"United-States"
}
data = json.dumps(sample)
# post to API and collect response
response = requests.post(url, data=data )
# display output - response will show sample details + model prediction added
print("response status code", response.status_code)
print("response content:")
print(response.json())