-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
30 lines (23 loc) · 908 Bytes
/
app.py
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
28
29
30
import pandas as pd
from fastapi import FastAPI
from lib.constants import ARTIFACTS_PATH
from lib.db import *
from lib.utils import *
from lib.transaction import Transaction
conn = create_db_connection()
app = FastAPI()
type_encoder, model, scaler = load_artifacts(ARTIFACTS_PATH)
@app.get("/")
async def root():
return {"message": "Hello World! :)"}
@app.post("/is-fraud")
async def is_fraud(transaction: Transaction):
insert_transaction(conn, dict(transaction))
filters = {"step": transaction.step, "nameOrig": transaction.nameOrig }
prev_transactions = query_transactions(conn, filters)
if len(list(prev_transactions)) >= 5: return { "isFraud": True }
transaction = transform(transaction, type_encoder)
features = to_dataframe(transaction)
features = normalize(features, scaler)
prediction = model.predict(features)[0]
return { "isFraud": bool(prediction) }