| | from fastapi import FastAPI, Request |
| | from pydantic import BaseModel |
| | import joblib |
| | import uvicorn |
| | import numpy as np |
| | import pandas as pd |
| |
|
| | app = FastAPI() |
| |
|
| | |
| | model = joblib.load("model_pipeline.pkl") |
| |
|
| | |
| | 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]) |
| | prediction = model.predict(df) |
| | return {"prediction": int(prediction[0])} |
| |
|
| | |
| | if __name__ == "__main__": |
| | uvicorn.run(app, host="0.0.0.0", port=7860) |