File size: 756 Bytes
a9d5138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Dict, Union
from fraud_detection_pipeline import load_pipeline

app = FastAPI()
pipeline = load_pipeline()

class PredictionInput(BaseModel):
    account_age: int
    cred_changes_freq: float
    return_order_ratio: float
    vpn_usage: int
    credit_score: int

@app.post("/predict")
async def predict(input_data: PredictionInput) -> Dict[str, Union[str, float]]:
    try:
        features = input_data.dict()
        prediction = pipeline._forward(features)
        return prediction
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.get("/")
async def root():
    return {"message": "Fraud Detection API is running"}