-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (40 loc) · 1.75 KB
/
app.py
File metadata and controls
53 lines (40 loc) · 1.75 KB
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
from fastapi import FastAPI, File, Query, UploadFile, HTTPException, Form
from fastapi.responses import FileResponse, PlainTextResponse
import uvicorn
import joblib
import numpy as np
from pydantic import BaseModel
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('credit_fraud.pkl')
@app.get("/", response_class=PlainTextResponse)
async def running():
note = """
Credit Card Fraud Detection API 🙌🏻
Note: add "/docs" to the URL to get the Swagger UI Docs or "/redoc"
"""
return note
favicon_path = 'favicon.png'
@app.get('/favicon.png', include_in_schema=False)
async def favicon():
return FileResponse(favicon_path)
class fraudDetection(BaseModel):
step:int
types:int
amount:float
oldbalanceorig:float
newbalanceorig:float
oldbalancedest:float
newbalancedest:float
isflaggedfraud:float
@app.post('/predict')
def predict(data : fraudDetection):
features = np.array([[data.step, data.types, data.amount, data.oldbalanceorig, data.newbalanceorig, data.oldbalancedest, data.newbalancedest, data.isflaggedfraud]])
model = joblib.load('credit_fraud.pkl')
predictions = model.predict(features)
if predictions == 1:
return {"fraudulent"}
elif predictions == 0:
return {"not fraudulent"}