Skip to content

Commit

Permalink
web app
Browse files Browse the repository at this point in the history
  • Loading branch information
alex000kim authored Sep 17, 2024
1 parent bf9730a commit 8279e3f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dvc
data
notebooks
reports
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.10
ENV PYTHONPATH=/app
WORKDIR /app
COPY . .
RUN pip install -U pip
RUN pip install -r requirements.txt
EXPOSE 8080
CMD uvicorn src.app.main:app --host 0.0.0.0 --port 8080
81 changes: 81 additions & 0 deletions src/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import json
import sys
from pathlib import Path

import uvicorn

src_path = Path(__file__).parent.parent.resolve()
sys.path.append(str(src_path))

from typing import List

import pandas as pd
from fastapi import Body, FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from joblib import load
from pydantic import BaseModel

from utils.load_params import load_params

app = FastAPI()
# https://fastapi.tiangolo.com/tutorial/cors/#use-corsmiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

params = load_params(params_path='params.yaml')
model_path = params.train.model_path
feat_cols = params.base.feat_cols
model = load(filename=model_path)

class Customer(BaseModel):
CreditScore: int
Age: int
Tenure: int
Balance: float
NumOfProducts: int
HasCrCard: int
IsActiveMember: int
EstimatedSalary: float

class Request(BaseModel):
data: List[Customer]

@app.post("/predict")
async def predict(info: Request = Body(..., example={
"data": [
{
"CreditScore": 619,
"Age": 42,
"Tenure": 2,
"Balance": 0,
"NumOfProducts": 1,
"HasCrCard": 1,
"IsActiveMember": 1,
"EstimatedSalary": 101348.88
},
{
"CreditScore": 699,
"Age": 39,
"Tenure": 21,
"Balance": 0,
"NumOfProducts": 2,
"HasCrCard": 0,
"IsActiveMember": 0,
"EstimatedSalary": 93826.63
}
]
})):
json_list = json.loads(info.json())
data = json_list['data']
input_data = pd.DataFrame(data)
probs = model.predict_proba(input_data)[:,0]
probs = probs.tolist()
return probs

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)

1 comment on commit 8279e3f

@alex000kim
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics

Path f1 roc_auc
metrics.json 0.53626 0.84193

Feature Importances

feature importance
num__Age 0.22
num__NumOfProducts 0.18
num__IsActiveMember 0.10
num__CreditScore 0.03
num__Balance 0.03
num__Tenure 0.02
num__HasCrCard 0.01
num__EstimatedSalary -0.00

Confusion Matrix

Please sign in to comment.