-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_api_request.py
More file actions
46 lines (36 loc) · 1.1 KB
/
Copy pathrender_api_request.py
File metadata and controls
46 lines (36 loc) · 1.1 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
'''
This script tests the live API by posting a set of input data, and checking whether the Render App
responses correctly by returning the predicted annual income category (over/under $50K).
Author: Gian Atmaja
Created: 6 May 2023
'''
# Import required libraries
import requests
import logging
# Set logging configurations
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)
# Input data
input_features = {
"age": 34,
"workclass": "Private",
"fnlgt": 302146,
"education": "Bachelors",
"education_num": 13,
"marital_status": "Divorced",
"occupation": "Craft-repair",
"relationship": "Husband",
"race": "Black",
"sex": " Male",
"capital_gain": 2135,
"capital_loss": 0,
"hours_per_week": 42,
"native_country": "United-States"
}
# POST to API
app_url = "https://fastapi-cloudapp.onrender.com/predict-income"
r = requests.post(app_url, json=input_features)
#assert r.status_code == 200
# Log response
logging.info("Testing Render app")
logging.info(f"Status code: {r.status_code}")
logging.info(f"Response body: {r.json()}")