Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import Dict, Union
|
| 4 |
+
from fraud_detection_pipeline import load_pipeline
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
pipeline = load_pipeline()
|
| 8 |
+
|
| 9 |
+
class PredictionInput(BaseModel):
|
| 10 |
+
account_age: int
|
| 11 |
+
cred_changes_freq: float
|
| 12 |
+
return_order_ratio: float
|
| 13 |
+
vpn_usage: int
|
| 14 |
+
credit_score: int
|
| 15 |
+
|
| 16 |
+
@app.post("/predict")
|
| 17 |
+
async def predict(input_data: PredictionInput) -> Dict[str, Union[str, float]]:
|
| 18 |
+
try:
|
| 19 |
+
features = input_data.dict()
|
| 20 |
+
prediction = pipeline._forward(features)
|
| 21 |
+
return prediction
|
| 22 |
+
except Exception as e:
|
| 23 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 24 |
+
|
| 25 |
+
@app.get("/")
|
| 26 |
+
async def root():
|
| 27 |
+
return {"message": "Fraud Detection API is running"}
|