subbunanepalli commited on
Commit
f4e32bc
·
verified ·
1 Parent(s): 927c3cd

Create predict.py

Browse files
Files changed (1) hide show
  1. predict.py +25 -0
predict.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import HTTPException
2
+ import pandas as pd
3
+ import joblib
4
+ from validate import TransactionData
5
+ from utils import create_text_input
6
+
7
+ MODEL_PATH = "models/logreg_model.pkl"
8
+
9
+ def predict(request: TransactionData):
10
+ try:
11
+ model = joblib.load(MODEL_PATH)
12
+ input_df = pd.DataFrame([request.dict()]).fillna("")
13
+ text_input = create_text_input(input_df.iloc[0])
14
+ prediction = model.predict([text_input])[0]
15
+
16
+ return {
17
+ "Maker_Action": prediction[0],
18
+ "Escalation_Level": prediction[1],
19
+ "Risk_Category": prediction[2],
20
+ "Risk_Drivers": prediction[3],
21
+ "Investigation_Outcome": prediction[4],
22
+ "Alert_Status": prediction[5]
23
+ }
24
+ except Exception as e:
25
+ raise HTTPException(status_code=500, detail=str(e))