AI-Powered Loan Decision System with OCR, LLM Extraction, and Explainable ML
Features β’ Architecture β’ Installation β’ API Docs β’ Demo
- Overview
- Features
- Architecture
- Technology Stack
- Installation
- Usage
- API Documentation
- Frontend Architecture
- Machine Learning Pipeline
- Contributing
- License
DenaAI is an intelligent loan underwriting system that combines cutting-edge AI technologies to automate and enhance the loan approval process. Built for financial institutions, it provides:
- π Automated Document Processing via OCR
- π€ AI-Powered Data Extraction using Groq LLM
- π― ML-Based Risk Assessment with XGBoost
- π Explainable AI for transparent decision-making
- π Bias Detection & Monitoring for fair lending
- π₯ Dual Interface for customers and bank officers
Traditional loan processing is slow, subjective, and prone to bias. DenaAI solves these problems by:
β
Reducing processing time from days to minutes
β
Providing transparent, explainable decisions
β
Detecting and preventing algorithmic bias
β
Supporting both automated and manual review workflows
β
Helping rejected applicants improve their applications
- π± Mobile-First Application - Apply for loans from anywhere
- πΈ Smart Document Upload - OCR automatically extracts data from income documents
- β‘ Instant Decisions - Get approval/rejection in seconds
- π‘ AI-Powered Guidance - Understand why you were rejected and how to improve
- π Application Tracking - Monitor your loan status in real-time
- π Loan History - View all past applications and outcomes
- π Manual Review Queue - Handle edge cases requiring human judgment
- π Comprehensive Dashboard - Monitor all applications
- π₯ User Management - Manage customer accounts
- π Analytics & Reports - Track approval rates and trends
- β Approval Workflow - Approve, reject, or request additional information
- π₯οΈ Web Monitoring Dashboard - Real-time system monitoring
- π― Bias Detection - Identify and mitigate algorithmic bias
- π Audit Logs - Complete audit trail of all decisions
- π Advanced Analytics - Deep insights with interactive graphs
- βοΈ System Configuration - Manage thresholds and rules
- π Secure authentication for users and admins
- π Complete audit trail for regulatory compliance
- π‘οΈ Data privacy protection
- βοΈ Fair lending compliance monitoring
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INTERACTION β
β π± Flutter Mobile App π₯οΈ Flutter Web Dashboard β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FASTAPI BACKEND β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Auth API β β Loan API β β Admin API β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββ¬ββββββββ β
βββββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PROCESSING LAYER β
β βββββββββββ ββββββββββββ βββββββββββ ββββββββββββ β
β β OCR ββ β Groq LLM ββ β Rules ββ β XGBoost β β
β β Service β βExtractionβ β Engine β β ML β β
β βββββββββββ ββββββββββββ βββββββββββ ββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
βΌ βΌ
Decision Result Explanation + Score
graph TD
A[User Uploads Document] --> B{User Type?}
B -->|New User| C[OCR Extraction]
B -->|Existing User| D[Fetch History]
C --> E[Groq LLM Parse Fields]
D --> E
E --> F[Rule-Based Checks]
F --> G[XGBoost Prediction]
G --> H{Decision}
H -->|Approved| I[Show Explanation]
H -->|Rejected| J[AI Help & Suggestions]
H -->|Uncertain| K[Manual Review Queue]
K --> L[Bank Officer Review]
I --> M[Store Audit Log]
J --> M
L --> M
- Framework: FastAPI 0.124.4
- ML Engine: XGBoost 3.1.2, Scikit-learn 1.6.1
- LLM: Groq (Llama 3.1-8B-Instant)
- OCR: OCR.space API
- Language: Python 3.10+
- Framework: Flutter 3.0+
- State Management: Provider/Riverpod
- Platforms: iOS, Android, Web
- Algorithm: XGBoost Gradient Boosting
- Features: 11 financial indicators
- Training Dataset:
loan_approval_dataset.csv - Model Format: Joblib pipeline
- API Documentation: Swagger UI (FastAPI auto-generated)
- Environment Management: Python dotenv
- Version Control: Git
- Python 3.10+
- Flutter SDK 3.0+
- Git
# Clone the repository
git clone https://github.com/Mehedi26696/Fintech.git
cd DenaAI/backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Create .env file
copy .env.example .env # Windows
cp .env.example .env # Linux/Mac
# Edit .env and add your API keys
# GROQ_API_KEY=your_groq_api_key
# OCR_SPACE_API_KEY=your_ocr_api_key
# Run the server
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000cd ../frontend
# Install dependencies
flutter pub get
# Run on desired platform
flutter run -d chrome # Web
flutter run -d windows # Windows
flutter run # Mobile (connect device/emulator)cd backend
uvicorn src.main:app --reload --port 8000Access the API documentation at: http://localhost:8000/docs
cd frontend
flutter runcurl http://localhost:8000/healthResponse:
{
"status": "healthy",
"service": "Loan Underwriting & Prediction System",
"version": "2.0.0"
}http://localhost:8000
POST /underwrite
Content-Type: multipart/form-data
Parameters:
- file: Document image/PDF (required)
- loan_amount: float (optional)
- loan_term: int (optional)
- cibil_score: int (optional)
- income_annum: float (optional)
- ... (other overrides)
Response:
{
"extracted": {...},
"rule_checks": {...},
"approval_probability": 0.78,
"decision": "Approved",
"explanation": "...",
"missing_fields": []
}POST /model/predict
Body:
{
"features": {
"no_of_dependents": 2,
"income_annum": 600000,
"loan_amount": 500000,
"loan_term": 12,
"cibil_score": 750,
...
},
"threshold": 0.5
}
Response:
{
"approval_probability": 0.82,
"decision": "Approved",
"threshold": 0.5
}POST /model/predict_batch
Body:
{
"records": [
{"features": {...}},
{"features": {...}}
],
"threshold": 0.5
}GET /model/schema
Response: Complete feature schema with descriptionsPOST /auth/login
POST /auth/signup
POST /auth/forgot-passwordfrontend/lib/
βββ core/ # Core configurations
β βββ config/ # App & API config
β βββ theme/ # App theme & colors
β βββ routes/ # Navigation
β βββ constants/ # Constants
β βββ utils/ # Utilities
β
βββ features/ # Feature modules
β βββ splash/ # Splash screen
β βββ onboarding/ # Onboarding flow
β βββ auth/ # Authentication
β β βββ screens/ # Login, signup, etc.
β β βββ widgets/ # Auth widgets
β β βββ services/ # Auth service
β β βββ models/ # User models
β β
β βββ user/ # User dashboard
β β βββ screens/ # Home, profile, settings
β β βββ widgets/ # Dashboard widgets
β β
β βββ loan/ # Loan management
β β βββ screens/ # Application, upload, status
β β β βββ loan_form_screen.dart
β β β βββ document_upload_screen.dart
β β β βββ loan_explanation_screen.dart
β β β βββ ai_help_screen.dart
β β β βββ loan_history_screen.dart
β β βββ widgets/ # Loan widgets
β β βββ services/ # Loan API services
β β βββ models/ # Loan models
β β
β βββ admin/ # Admin (mobile/tablet)
β β βββ screens/ # Management screens
β β β βββ manual_review_screen.dart
β β β βββ review_detail_screen.dart
β β βββ widgets/ # Admin widgets
β β βββ services/ # Admin services
β β βββ models/ # Admin models
β β
β βββ admin_web/ # Web-only monitoring
β βββ screens/ # Web dashboards
β β βββ admin_dashboard.dart
β β βββ bias_monitor.dart
β β βββ audit_log.dart
β β βββ graphs.dart
β βββ widgets/ # Web widgets
β βββ services/ # Monitoring services
β βββ models/ # Monitoring models
β
βββ shared/ # Shared components
βββ widgets/ # Reusable widgets
βββ services/ # HTTP, storage, etc.
βββ models/ # Common models
βββ exceptions/ # Error handling
βββ extensions/ # Dart extensions
cd backend
jupyter notebook "Training Code.ipynb"- no_of_dependents - Number of dependents
- income_annum - Annual income
- loan_amount - Requested loan amount
- loan_term - Loan term in months
- cibil_score - Credit score (300-900)
- residential_assets_value - Residential property value
- commercial_assets_value - Commercial property value
- luxury_assets_value - Luxury assets value
- bank_asset_value - Bank deposits/savings
- education - Education level (encoded)
- self_employed - Employment type (binary)
- Algorithm: XGBoost with hyperparameter tuning
- Training Accuracy: ~95%
- Validation Accuracy: ~92%
- F1 Score: ~0.91
- Model File:
loan_xgb_pipeline.joblib
Business rules applied before ML prediction:
- β Income reasonability check
- β CIBIL score minimum threshold
- β Loan-to-income ratio validation
- β Missing field detection
- β OCR confidence validation
Every decision comes with:
- Probability score
- Rule check results
- Feature importance
- Clear explanation text
Web dashboard monitors:
- Approval rate by demographics
- Score distribution fairness
- Statistical parity checks
- Disparate impact analysis
Rejected applicants receive:
- Reasons for rejection
- Actionable improvement suggestions
- What-if scenario analysis
- Personalized guidance via Groq LLM
Automatic Approval β User gets instant result
Automatic Rejection β AI help + explanation
Uncertain Cases β Manual review by officer
Create a .env file in the backend/ directory:
# API Configuration
API_TITLE=Loan Underwriting & Prediction System
API_VERSION=2.0.0
DEBUG=False
# ML Model
MODEL_PATH=loan_xgb_pipeline.joblib
DEFAULT_APPROVAL_THRESHOLD=0.5
# OCR Service
OCR_SPACE_API_KEY=your_ocr_api_key_here
OCR_SPACE_BASE_URL=https://api.ocr.space/parse/image
# Groq API
GROQ_API_KEY=your_groq_api_key_here
GROQ_BASE_URL=https://api.groq.com/openai/v1/chat/completions
GROQ_MODEL=llama-3.1-8b-instant
# Optional: Gemini API (backup)
GEMINI_API_KEY=your_gemini_api_key_here- Groq API: https://console.groq.com/
- OCR.space: https://ocr.space/ocrapi
- Gemini API: https://ai.google.dev/
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PEP 8 for Python code
- Follow Flutter/Dart style guide
- Write tests for new features
- Update documentation
This project is licensed under the MIT License - see the LICENSE file for details.
DenaAI Development Team
| H.M. Mehedi Hasan Backend & ML Development | Chowdhury Shafahid Rahman API Integration | Sumaiya Rahman Soma UX/UI & Bias Detection | MD. Abu Bakar Siddique Frontend Development |
- FastAPI for the excellent web framework
- XGBoost team for the ML library
- Groq for LLM API access
- OCR.space for document processing
- Flutter team for the cross-platform framework
For support, email support@denai.com or open an issue on GitHub.