-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
104 lines (84 loc) · 2.7 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn
import numpy as np
import pandas as pd
from fastapi.middleware.cors import CORSMiddleware
from prediction_model.predict import generate_predictions
app = FastAPI(
title="Credit Decision Model API",
description="A FastAPI application for automating credit decision evaluations. It utilizes a machine learning model to predict loan approval outcomes based on customer information.",
version="1.0"
)
origins=[
"*"
]
app.add_middleware(
CORSMiddleware,
allow_origins = origins,
allow_credentials = True,
allow_methods = ["*"],
allow_headers= ["*"]
)
class LoanApplication(BaseModel):
rate: float
amount: float
purpose: str
period: int
cus_age: int
gender: str
education_level: str
marital_status: str
has_children: str
living_situation: str
total_experience: int
income: float
job_sector: str
DTI: float
APR: float
ccr_tot_mounth_amt: float
ccr_payed_loan_tot_amt: float
ccr_act_loan_tot_rest_amt: float
@app.get("/")
def index():
return {"message": "Welcome to Credit Decision Model APP"}
@app.post("/prediction_api")
def predict_loan_approval(loan_details: LoanApplication):
data = loan_details.dict()
prediction = generate_predictions([data])["Predictions"][0]
return {"Status": prediction}
@app.post("/prediction_ui")
def predict_loan_approval_form(
rate: float,
amount: float,
purpose: str,
period: int,
cus_age: int,
gender: str,
education_level: str,
marital_status: str,
has_children: str,
living_situation: str,
total_experience: int,
income: float,
job_sector: str,
DTI: float,
APR: float,
ccr_tot_mounth_amt: float,
ccr_payed_loan_tot_amt: float,
ccr_act_loan_tot_rest_amt: float):
input_data = [rate, amount, purpose, period, cus_age,
gender, education_level, marital_status, has_children,
living_situation, total_experience, income,
job_sector, DTI, APR, ccr_tot_mounth_amt,
ccr_payed_loan_tot_amt, ccr_act_loan_tot_rest_amt]
cols = ["rate", "amount", "purpose", "period", "cus_age",
"gender", "education_level", "marital_status", "has_children",
"living_situation", "total_experience", "income", "job_sector",
"DTI", "APR", "ccr_tot_mounth_amt",
"ccr_payed_loan_tot_amt", "ccr_act_loan_tot_rest_amt"]
data_dict = dict(zip(cols, input_data))
prediction = generate_predictions([data_dict])["Predictions"][0]
return {"Status": prediction}
if __name__=="__main__":
uvicorn.run(app, host="0.0.0.0", port=8005)