RFA-Model-CAS-API / slapp.py
LazyBoss's picture
Update slapp.py
07eb06b verified
raw
history blame
725 Bytes
from fastapi import FastAPI
import pickle
import pandas as pd
# Load the saved model
def load_model():
try:
model = pickle.load(open('model.pkl', 'rb'))
return model
except Exception as e:
raise RuntimeError(f"Error loading model: {e}")
model = load_model()
app = FastAPI()
@app.post("/predict")
async def predict_transaction(data: dict):
try:
# Convert the input data to a DataFrame
transaction_data = pd.DataFrame([data])
prediction = model.predict(transaction_data)
result = "Fraudulent transaction" if prediction[0] == 1 else "Acceptable transaction"
return {"prediction": result}
except Exception as e:
return {"error": str(e)}