Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +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=
|
|
|
|
| 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=7860)
|