Skip to content

Shreyas-S-809/The-Active-Sentinel-Human-in-the-Loop-Risk-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

The Active Sentinel โ€” Human-in-the-Loop Loan Risk Engine

Python FastAPI Streamlit License Live Demo

Goal:
Build a production-oriented loan risk prediction system that not only makes decisions, but learns from human corrections and monitors its own performance in real time.


๐ŸŽฏ Motivation

Most ML projects end at model.predict(). Real-world systems continue long after deployment. The Active Sentinel bridges this gap by simulating how deployed ML systems handle uncertainty, collect corrections, and evolve post-deployment.


๐Ÿ’ก Why This Project Exists

Financial institutions don't just need accurate modelsโ€”they need accountable, auditable systems that:

  • Operate under regulatory scrutiny
  • Handle edge cases through human oversight
  • Adapt to data drift and changing risk patterns

๐Ÿ—๏ธ Core Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Streamlit Frontend     โ”‚  User interaction & feedback collection
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚ HTTPS
            โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  FastAPI Backend        โ”‚  Inference API + feedback logging
โ”‚  (Render)               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ†“                โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ RF Modelโ”‚    โ”‚ SQLite DBโ”‚
โ”‚ (.pkl)  โ”‚    โ”‚ Feedback โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Stack:

  • Backend: FastAPI (stateless inference service)
  • Frontend: Streamlit (user interface)
  • Model: Random Forest (scikit-learn)
  • Storage: SQLite (feedback persistence)
  • Deployment: Render (HTTPS endpoints)

โœจ Key Features

Inference

  • REST API with /predict, /feedback, and /stats endpoints
  • Confidence-scored predictions with interpretability
  • Stateless service design for horizontal scaling

๐Ÿ”„ Human-in-the-Loop Validation

  • Real-time feedback mechanism (Correct/Incorrect labels)
  • Persistent storage for post-deployment analysis
  • Simulates domain expert review workflows

Live Performance Monitoring

  • Dynamic accuracy computation from user corrections
  • Transparent model reliability metrics
  • Feedback-driven evaluation dashboards

๐Ÿš€ Deployment-Aware Design

  • Independent backend/frontend services
  • Production-grade API contracts & Scalable

Use Cases

Scenario Application
Loan Origination Risk officers review and override model decisions
Insurance Underwriting Human adjustors provide ground truth labels
Fraud Detection Security analysts validate alert accuracy

๐ŸŒ Deployment Guide

Check out the live demo at: https://the-active-sentinel.streamlit.app/

Backend (FastAPI)

# Deployed on Render
# Exposes inference API at: https://active-sentinel.onrender.com

Frontend (Streamlit)

# Configure backend URL in app
# Run locally or deploy to Streamlit Cloud
streamlit run app.py

โš ๏ธ Cold Start Behavior

Render's free tier auto-sleeps inactive services. First request after inactivity may take 30-60 secondsโ€”this is expected.


๐ŸŽ“ What This Demonstrates

End-to-end ML system design
API-based inference (production patterns vs. notebook code)
Feedback integration (human-in-the-loop workflows)
Live monitoring (post-deployment performance tracking)
Deployment trade-offs (cold starts, stateless services, persistence)


๐Ÿ› ๏ธ Technical Decisions

Choice Rationale
FastAPI Async support, auto-generated docs, type safety
SQLite Zero-config persistence for MVP; easy migration to PostgreSQL
Random Forest Interpretable, handles mixed data types, production-proven
Render Free Tier Demonstrates real deployment constraints (cold starts)
Separate Backend/Frontend Mirrors microservices architecture, independent scaling

๐Ÿ”ฎ Future Enhancements

  • PostgreSQL migration for multi-user persistence
  • Scheduled retraining pipeline using collected feedback
  • Drift detection alerts (PSI, KS tests, data quality monitoring)
  • Role-based access control for feedback validation workflows
  • A/B testing framework for model version comparison

๐Ÿ’ญ Project Philosophy

"This project is intentionally simple in modeling and strong in system design."

The goal isn't chasing 99% accuracyโ€”it's about demonstrating how ML systems operate after deployment:

  • How feedback gets collected
  • How performance is monitored
  • How humans stay in the loop

๐Ÿš€ Getting Started

# Clone repository
git clone https://github.com/Shreyas-S-809/The-Active-Sentinel-Human-in-the-Loop-Risk-Engine
cd The-Active-Sentinel-Human-in-the-Loop-Risk-Engine

# Install dependencies
pip install -r requirements.txt

# Run backend locally
uvicorn api:app --reload

# Run frontend (separate terminal)
streamlit run app.py

๐Ÿ–ฅ๏ธ Running the Project Locally (Important)

This project is deployed using a separated frontendโ€“backend architecture. When running the system locally, a few configuration changes are required to avoid environment-specific issues.

1๏ธโƒฃ Update API Endpoint for Local Development

The Streamlit frontend communicates with the FastAPI backend via an API URL.

When deployed, the frontend points to the Render-hosted backend:

API_URL = "https://active-sentinel.onrender.com"

For local development, update this in frontend/app.py:

API_URL = "http://127.0.0.1:8000"

This ensures the frontend correctly connects to the locally running FastAPI server.

โš ๏ธ If this change is not made, the frontend will attempt to call the deployed API, resulting in connection errors.

2๏ธโƒฃ Install Local-Only Dependencies

During deployment, the backend and frontend were separated to meet platform constraints. When running the project locally, the frontend requires additional packages.

Ensure the following dependencies are present in requirements.txt:

streamlit
requests

Then install all dependencies using:

pip install -r requirements.txt

These packages are required only for local execution of the Streamlit UI and are intentionally excluded from the backend-only deployment environment.

3๏ธโƒฃ Start Both Services

Terminal 1 โ€“ Start FastAPI Backend

uvicorn api.main:app --reload

Terminal 2 โ€“ Start Streamlit Frontend

streamlit run frontend/app.py

Access Points:

  • Backend: http://127.0.0.1:8000
  • Frontend: http://localhost:8501

๐Ÿ“„ License

MIT License - See LICENSE for details.


๐Ÿ“ฌ Contact

Shreyas S
GitHub | LinkedIn


โญ Star this repo if you found it helpful!

About

Self-correcting loan risk prediction system with human-in-the-loop feedback and live monitoring.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published