Spaces:
Sleeping
Sleeping
| 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() | |
| 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)} | |