Spaces:
Sleeping
Sleeping
| from fastapi import HTTPException | |
| import pandas as pd | |
| import joblib | |
| from validate import TransactionData | |
| from utils import create_text_input | |
| MODEL_PATH = "models/logreg_model.pkl" | |
| def predict(request: TransactionData): | |
| try: | |
| model = joblib.load(MODEL_PATH) | |
| input_df = pd.DataFrame([request.dict()]).fillna("") | |
| text_input = create_text_input(input_df.iloc[0]) | |
| prediction = model.predict([text_input])[0] | |
| return { | |
| "Maker_Action": prediction[0], | |
| "Escalation_Level": prediction[1], | |
| "Risk_Category": prediction[2], | |
| "Risk_Drivers": prediction[3], | |
| "Investigation_Outcome": prediction[4], | |
| "Alert_Status": prediction[5] | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |