-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
37 lines (29 loc) · 857 Bytes
/
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
from http import HTTPStatus
from fastapi import FastAPI
from src.data_handler import Sample
# Define application
app = FastAPI()
# Check the connection is OK by initial path
@app.get("/")
def _health_check() -> dict:
response = {
"message": HTTPStatus.OK.phrase,
"status-code": HTTPStatus.OK,
"data": {},
}
return response
@app.post("/predict_car_price/")
def _get_sample(sample: Sample) -> dict:
"""Receive a sample as dataclass, handle the sample
then display the price as integer type.
Args:
sample (Sample): contains the features value.
Returns:
dict: response information contains the sample as string type.
"""
response = {
"message": HTTPStatus.OK.phrase,
"status-code": HTTPStatus.OK,
"price": int(sample.price[0])
}
return response