-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (54 loc) · 1.84 KB
/
main.py
File metadata and controls
66 lines (54 loc) · 1.84 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from ml_utils import load_dataset,predict
from datetime import datetime
from fastapi.staticfiles import StaticFiles
##from fastapi.encoders import jsonable_encoder
##from fastapi.responses import JSONResponse
##from pydantic import BaseModel
from fastapi.responses import FileResponse
app = FastAPI( title="CredScore Application",docs_url="/")
##app.mount("/static", StaticFiles(directory="static"), name="static")
app.add_event_handler("startup", load_dataset)
class QueryIn(BaseModel):
existing_checking_account :str
duration_in_month :int
credit_history :str
purpose :str
credit_amount :int
savings_account_bonds :str
present_employment_since :str
percentage_of_disposable_income :int
personal_status_and_sex :str
other_debtors_guarantors :str
present_residence_since :int
property :str
age_in_years :int
other_installment_plans :str
housing :str
number_of_existing_credits_at_this_bank :int
job :str
number_of_people_being_liable :int
telephone :str
foreign_worker :str
class QueryOut(BaseModel):
is_trusted_customer: str
timestamp_str:str
@app.get("/ping")
def ping():
return {"ping": "pong"}
@app.post("/predict_customer", response_model=QueryOut, status_code=200)
async def predict_customer( query_data: QueryIn):
print(f"query_data={query_data}")
result = predict(query_data)
ct = datetime.now()
ctStr = ct.strftime("%m/%d/%Y, %H:%M:%S")
output = {'is_trusted_customer': result,'timestamp_str':ctStr}
print(f"output={output}")
return output
@app.get("/demo",response_class=FileResponse)
async def demo():
return FileResponse("static/CredScore_Application.html")
if __name__ == "__main__":
uvicorn.run("main:app", host='127.0.0.1', port=8088, reload=True)