Spaces:
Sleeping
Sleeping
File size: 725 Bytes
07eb06b 75570c3 07eb06b 75570c3 07eb06b 75570c3 07eb06b 75570c3 07eb06b | 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 | 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)}
|