Upload 3 files
Browse files- fast_api.py +39 -0
- model_pipeline.pkl +3 -0
- requirements.txt +7 -0
fast_api.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import joblib
|
| 4 |
+
import uvicorn
|
| 5 |
+
import numpy as np
|
| 6 |
+
import pandas as pd
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
# Load model (ganti dengan path model kamu)
|
| 11 |
+
model = joblib.load("model_pipeline.pkl")
|
| 12 |
+
|
| 13 |
+
# Define input format
|
| 14 |
+
class CustomerInput(BaseModel):
|
| 15 |
+
credit_score: int
|
| 16 |
+
country: str
|
| 17 |
+
gender: str
|
| 18 |
+
age: int
|
| 19 |
+
tenure: int
|
| 20 |
+
balance: float
|
| 21 |
+
products_number: int
|
| 22 |
+
credit_card: int
|
| 23 |
+
active_member: int
|
| 24 |
+
estimated_salary: float
|
| 25 |
+
|
| 26 |
+
@app.get("/")
|
| 27 |
+
def read_root():
|
| 28 |
+
return {"message": "Model REST API is up!"}
|
| 29 |
+
|
| 30 |
+
@app.post("/predict")
|
| 31 |
+
def predict_customer(input: CustomerInput):
|
| 32 |
+
data = input.dict()
|
| 33 |
+
df = pd.DataFrame([data]) # bentuk tabular
|
| 34 |
+
prediction = model.predict(df)
|
| 35 |
+
return {"prediction": int(prediction[0])}
|
| 36 |
+
|
| 37 |
+
# Only needed for local testing
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
model_pipeline.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:04706238f5c6f50ec5461057a6d9a12e7a8c90cdf86a084b0f496769a31094bd
|
| 3 |
+
size 103024
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
joblib
|
| 4 |
+
numpy
|
| 5 |
+
pandas
|
| 6 |
+
scikit-learn
|
| 7 |
+
xgboost
|