-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
89 lines (76 loc) · 2.32 KB
/
main.py
File metadata and controls
89 lines (76 loc) · 2.32 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from fastapi import FastAPI
import os
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
from prometheus_fastapi_instrumentator import Instrumentator
port = int(os.environ.get("PORT", 8005))
app = FastAPI(
title="Loan Prediction App using API - CI CD Jenkins",
description = "A Simple CI CD Demo",
version='1.0'
)
origins=[
"*"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
class LoanPrediction(BaseModel):
Gender: str
Married: str
Dependents: str
Education: str
Self_Employed: str
ApplicantIncome: float
CoapplicantIncome: float
LoanAmount: float
Loan_Amount_Term: float
Credit_History: float
Property_Area: str
@app.get("/")
def index():
return {"message":"Welcome to Loan Prediction App using API - CI CD Jenkins" }
@app.post("/prediction_api")
def predict(loan_details: LoanPrediction):
data = loan_details.model_dump()
prediction = generate_predictions([data])["prediction"][0]
if prediction == "Y":
pred = "Approved"
else:
pred = "Rejected"
return {"status":pred}
@app.post("/prediction_ui")
def predict_gui(Gender: str,
Married: str,
Dependents: str,
Education: str,
Self_Employed: str,
ApplicantIncome: float,
CoapplicantIncome: float,
LoanAmount: float,
Loan_Amount_Term: float,
Credit_History: float,
Property_Area: str):
input_data = [Gender, Married,Dependents, Education, Self_Employed,ApplicantIncome,
CoapplicantIncome,LoanAmount, Loan_Amount_Term,Credit_History, Property_Area ]
cols = ['Gender', 'Married', 'Dependents', 'Education',
'Self_Employed', 'ApplicantIncome', 'CoapplicantIncome', 'LoanAmount',
'Loan_Amount_Term', 'Credit_History', 'Property_Area']
data_dict = dict(zip(cols,input_data))
prediction = generate_predictions([data_dict])["prediction"][0]
if prediction == "Y":
pred = "Approved"
else:
pred = "Rejected"
return {"status":pred}
if __name__== "__main__":
uvicorn.run("main:app", host="0.0.0.0",port=port,reload=False)
Instrumentator().instrument(app).expose(app)