-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (30 loc) · 1.02 KB
/
main.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
"""
Example file of interaction with the FastAPI server.
Author
------
Nicolas Rojas
"""
# This script shows how to interact with the API serving the model
# Given the context of this problem, a simple program sending a request makes
# more sense than a graphical user interface, although building one with
# libraries like gradio or streamlit would be trivial given the current script
import requests
ENDPOINT_URL = "http://localhost:8086/predict/"
try:
data = {
"id": 0,
"age": 35.0,
"annual_income": 107770.0,
"credit_score": 331.0,
"loan_amount": 31580.0,
"loan_duration_years": 28,
"number_of_open_accounts": 13.0,
"had_past_default": 0,
}
response = requests.post(ENDPOINT_URL, json=data, timeout=30)
if response.status_code == 200:
print(response.json())
else:
print(f"Failed with status code: {response.status_code}")
except requests.exceptions.RequestException as error:
print(f"Failed to connect to FastAPI server:\n{error}")