-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsend_data-api.py
40 lines (34 loc) · 1.5 KB
/
send_data-api.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
import os
import json
from time import sleep
import pyarrow.csv as pcsv
import requests
SERVE_ADDRESS = os.getenv('SERVE_ADDRESS', 'http://127.0.0.1:9696')
full_path = f'{SERVE_ADDRESS}/predict'
table = pcsv.read_csv("input_clean/credit_card_churn_clean.csv")
data = table.to_pylist()
# {'': 0, 'customer_id': 768805383, 'customer_age': 45, 'gender': 'M', 'dependent_count': 3, 'education_level': 1, 'marital_status': 'married',
# 'income_category': 2, 'card_category': 'blue', 'months_on_book': 39, 'total_relationship_count': 5, 'credit_limit': 12691.0,
# 'total_revolving_bal': 777, 'active_customer': True}
while True:
for row in data:
payload = {
'customer_age': row['customer_age'],
'gender': row['gender'],
'dependent_count': row['dependent_count'],
'education_level': row['education_level'],
'marital_status': row['marital_status'],
'income_category': row['income_category'],
'card_category': row['card_category'],
'months_on_book': row['months_on_book'],
'total_relationship_count': row['total_relationship_count'],
'credit_limit': row['credit_limit'],
'total_revolving_bal': row['total_revolving_bal'],
}
print(f'Request from {full_path}, payload: {payload}')
resp = requests.post(full_path,
headers={"Content-Type": "application/json"},
data=json.dumps(row)) \
.json()
print(f"Response: {resp}\n")
sleep(60) #sec