-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapicalls.py
More file actions
40 lines (28 loc) · 1.16 KB
/
apicalls.py
File metadata and controls
40 lines (28 loc) · 1.16 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
"""
Python script meant to call your API endpoints.
"""
import requests
import os
import json
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
# Specify a URL that resolves to your workspace.
URL = "http://127.0.0.1:8000"
# Call each API endpoint and store the responses.
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
response1 = requests.post("%s/prediction" % URL, json={"dataset_path": "testdata.csv"}, headers=headers).text
response2 = requests.get("%s/scoring" % URL, headers=headers).text
response3 = requests.get("%s/summarystats" % URL, headers=headers).text
response4 = requests.get("%s/diagnostics" % URL, headers=headers).text
# Combine all API responses.
responses = response1 + "\n" + response2 + "\n" + response3 + "\n" + response4
# Write the responses to your workspace.
with open('config.json', 'r') as f:
"""
Load config.json and correct path variable.
"""
config = json.load(f)
model_path = os.path.join(config['output_model_path'])
with open(os.path.join(model_path, "apireturns.txt"), "w") as returns_file:
returns_file.write(responses)