Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use Python 3.9 slim image
FROM python:3.9-slim

# Set working directory
WORKDIR /app

# Copy requirements and install
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy source code
COPY src/ ./src/

# Expose port
EXPOSE 8000

# Run the application
CMD ["uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000"]
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.8'

services:
api:
build: .
ports:
- "8000:8000"
volumes:
- ./mlruns:/app/mlruns # If MLflow uses local storage
environment:
- MLFLOW_TRACKING_URI=http://localhost:5000 # If running MLflow server separately
Empty file added src/api/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions src/api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from fastapi import FastAPI
import mlflow.sklearn
import pandas as pd
from .pydantic_models import TransactionData, PredictionResponse

app = FastAPI(title="Credit Risk Prediction API", version="1.0.0")

# Load the model from MLflow registry
model_name = "CreditRiskLogisticRegression"
model_version = "latest" # or specify version
model = mlflow.sklearn.load_model(f"models:/{model_name}/{model_version}")

@app.post("/predict", response_model=PredictionResponse)
def predict_risk(transaction: TransactionData):
# Convert to DataFrame
data = pd.DataFrame([transaction.dict()])

# Predict probability
proba = model.predict_proba(data)[:, 1][0]

# Predict class
prediction = model.predict(data)[0]

return PredictionResponse(
risk_probability=float(proba),
is_high_risk=bool(prediction)
)

@app.get("/")
def read_root():
return {"message": "Credit Risk Prediction API"}
17 changes: 17 additions & 0 deletions src/api/pydantic_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pydantic import BaseModel
from typing import Optional

class TransactionData(BaseModel):
CurrencyCode: str
CountryCode: int
ProviderId: str
ProductId: str
ProductCategory: str
ChannelId: str
Amount: float
Value: int
PricingStrategy: int

class PredictionResponse(BaseModel):
risk_probability: float
is_high_risk: bool