-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (51 loc) · 1.7 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from fastapi import FastAPI, File
from fastapi.responses import FileResponse, HTMLResponse
import uvicorn
import joblib
import numpy as np
from pydantic import BaseModel
import os
app = FastAPI(
title="Credit Card Fraud Detection API",
description="An API that utilises a Machine Learning model that detects if a credit card transaction is fraudulent or not based on the following features: hours, amount, transaction type etc.",
version="1.0.0",
debug=True
)
model = joblib.load('objects/credit_fraud.pkl');
@app.get("/", response_class=HTMLResponse)
async def running():
home = open(os.path.join("frontend/index.html"), 'r');
html = home.read();
home.close()
return html
favicon_path = 'favicon.png'
@app.get('/favicon.png', include_in_schema=False)
async def favicon():
return FileResponse(favicon_path)
class CreditData(BaseModel):
step: int;
types: int;
amount: float;
oldbalanceorig: float;
newbalanceorig: float;
oldbalancedest: float;
newbalancedest: float;
isFlaggedFraud: int;
@app.post('/predict/')
def predict(data: CreditData):
print(data)
features = np.array( [[data.step,
data.types,
data.amount,
data.oldbalanceorig,
data.newbalanceorig,
data.oldbalancedest,
data.newbalancedest,
data.isFlaggedFraud
]] );
model = joblib.load('objects/credit_fraud.pkl');
predictions = model.predict(features);
if (predictions == 1):
return {"fraudulent"}
elif (predictions == 0):
return {"not fraudulent"}