| 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 | |
| def read_root(): | |
| return {"message": "Model REST API is up!"} | |
| 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=8000) |