File size: 902 Bytes
5df38b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Request
from pydantic import BaseModel
import joblib
import uvicorn
import numpy as np
import pandas as pd

app = FastAPI()

# Load model (ganti dengan path model kamu)
model = joblib.load("model_pipeline.pkl")

# Define input format
class CustomerInput(BaseModel):
    credit_score: int
    country: str
    gender: str
    age: int
    tenure: int
    balance: float
    products_number: int
    credit_card: int
    active_member: int
    estimated_salary: float

@app.get("/")
def read_root():
    return {"message": "Model REST API is up!"}

@app.post("/predict")
def predict_customer(input: CustomerInput):
    data = input.dict()
    df = pd.DataFrame([data])  # bentuk tabular
    prediction = model.predict(df)
    return {"prediction": int(prediction[0])}

# Only needed for local testing
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)