Skip to content

ghanshambordekar3/SmartLend-AI

Repository files navigation

🤖 SmartLend.AI - AI-Powered Personal Loan Assistant

Clarity and trust in personal loan decisions

SmartLend.AI is a production-ready, AI-powered personal loan recommendation system that analyzes financial profiles and provides transparent, explainable loan decisions with personalized improvement suggestions.


🎯 Features

Core AI Capabilities

  • Intelligent Loan Scoring: ML-style multi-factor scoring algorithm with weighted feature analysis
  • Dynamic Risk Assessment: Real-time risk categorization (Low/Medium/High)
  • Approval Probability Prediction: AI-powered likelihood scoring with model uncertainty
  • Smart Loan Recommendations: Optimal loan amount, dynamic interest rates, and EMI calculations
  • Explainable AI: Transparent decision-making with detailed explanations
  • Personalized Suggestions: Actionable improvement recommendations based on financial profile

Technical Features

  • Frontend: Responsive HTML/CSS/JavaScript with modern UI/UX
  • Backend: Flask REST API with comprehensive error handling
  • AI Engine: Sophisticated scoring system simulating ML model behavior
  • Security: Input validation, CORS protection, rate limiting ready
  • Production Ready: Clean architecture, logging, health checks

📁 Project Structure

SmartLend.AI/
├── backend/
│   ├── app.py              # Flask REST API server
│   ├── ai_engine.py        # AI recommendation engine
│   └── requirements.txt    # Python dependencies
└── frontend/
    ├── index.html          # Main UI
    ├── styles.css          # Styling
    └── script.js           # Frontend logic

🚀 Quick Start

Prerequisites

  • Python 3.8+
  • pip (Python package manager)
  • Modern web browser

Installation & Setup

Step 1: Clone/Download the Project

# Create project directory
mkdir SmartLend.AI
cd SmartLend.AI

Step 2: Set Up Backend

# Navigate to backend directory
cd backend

# Install Python dependencies
pip install -r requirements.txt

# Start Flask server
python app.py

The backend server will start at http://localhost:5000

You should see:

🚀 SmartLend.AI Backend Server Starting...
📍 API Endpoint: http://localhost:5000/ai-loan-recommendation
🏥 Health Check: http://localhost:5000/health

Step 3: Launch Frontend

# Open a new terminal
cd frontend

# Open index.html in your browser
# Option 1: Double-click index.html
# Option 2: Use Python's built-in server
python -m http.server 8000
# Then visit http://localhost:8000

🎮 Usage Guide

1. Landing Page

  • Click "Analyze My Loan" to begin

2. Financial Profile Input

Fill in the following details:

  • Monthly Income: Your gross monthly salary (₹)
  • Employment Type: Salaried / Self-Employed / Business / Freelancer
  • Credit Score: Your CIBIL score (300-850)
  • Existing EMIs: Current monthly loan obligations (₹)
  • Requested Loan Amount: Desired loan amount (₹)
  • Loan Tenure: Repayment period (1-30 years)

3. AI Analysis Results

View comprehensive recommendation:

  • Approval Probability: Percentage likelihood of approval
  • Risk Assessment: Low / Medium / High risk category
  • Recommended Loan Terms:
    • Optimal loan amount
    • Dynamic interest rate
    • Monthly EMI
  • AI Explanation: Why the decision was made
  • Improvement Tips: Personalized suggestions to enhance eligibility

🧠 AI Engine Logic

Feature Engineering

The AI engine transforms raw financial data into ML-ready features:

  1. Credit Score Normalization (35% weight)

    • Normalized 300-850 scale
    • Higher scores = better approval odds
  2. Income Stability (25% weight)

    • Monthly income assessment
    • Employment type consideration
  3. Debt-to-Income Ratio (20% weight)

    • Existing EMI vs. income
    • Lower DTI = higher capacity
  4. Loan-to-Income Ratio (15% weight)

    • Requested amount vs. annual income
    • Reasonable borrowing limits
  5. Employment Security (5% weight)

    • Salaried > Self-Employed > Business > Freelancer

Decision Algorithm

AI Score = Σ(weighted_features × transformation_function)
Approval Probability = sigmoid(AI_Score)
Risk Level = threshold_based_classification(AI_Score)
Interest Rate = base_rate + risk_adjustment + credit_adjustment + market_factor

Dynamic Interest Rate Calculation

  • Base Rate: 9.5% (market baseline)
  • Credit Score Impact: -1.5% to +2.0%
  • Risk Adjustment: 0% to +2.5%
  • Tenure Factor: +0.1% per year
  • Market Volatility: ±0.3% (simulated)

🔌 API Documentation

Endpoint: /ai-loan-recommendation

Request

POST /ai-loan-recommendation
Content-Type: application/json

{
  "monthly_income": 50000,
  "employment_type": "salaried",
  "credit_score": 750,
  "existing_emi": 5000,
  "requested_amount": 500000,
  "tenure": 5
}

Response

{
  "success": true,
  "data": {
    "approval_probability": 78.45,
    "risk_level": "Low",
    "recommended_loan_amount": 450000,
    "interest_rate": 9.2,
    "monthly_emi": 9367.50,
    "ai_explanation": "✓ Strong approval likelihood...",
    "improvement_suggestions": [
      "✅ Excellent financial profile!"
    ],
    "ai_score": 82.3
  }
}

Health Check: /health

GET /health

Response:
{
  "status": "healthy",
  "ai_engine": "operational",
  "timestamp": "2025-01-04T00:00:00Z"
}

🛡️ Security & Best Practices

Input Validation

  • All inputs validated on both frontend and backend
  • Range checks (credit score: 300-850, tenure: 1-30 years)
  • Type validation (numbers, strings)
  • SQL injection prevention (no database in this version)

CORS Configuration

  • Enabled for cross-origin requests
  • Configure allowed origins for production

Error Handling

  • Comprehensive try-catch blocks
  • User-friendly error messages
  • Detailed logging for debugging

Responsible AI

  • Transparent decision-making
  • Encourages responsible borrowing
  • No discriminatory bias in scoring

🎨 UI/UX Features

Design Principles

  • Trust Colors: Blue, white, grey (financial trust)
  • Card-Based Layout: Clean, organized information
  • Responsive Design: Mobile-first approach
  • Smooth Animations: Professional but minimal
  • Accessibility: High contrast, semantic HTML

User Flow

  1. Landing → Engaging introduction with trust badges
  2. Form → Clear input fields with helpful hints
  3. Results → Comprehensive dashboard with visual indicators
  4. Actions → Easy navigation between sections

🔧 Customization Guide

Adjust AI Weights

Edit backend/ai_engine.py:

WEIGHTS = {
    'credit_score': 0.35,      # Increase for credit-focused
    'income_stability': 0.25,
    'debt_to_income': 0.20,
    'loan_to_income': 0.15,
    'employment_security': 0.05
}

Modify Interest Rate Logic

def _calculate_dynamic_interest_rate(self, credit_score, risk_level, tenure):
    base_rate = 9.5  # Change market base rate
    # Adjust credit score brackets
    # Modify risk premiums

Change UI Colors

Edit frontend/styles.css:

:root {
    --primary-blue: #2563eb;   /* Brand color */
    --success-green: #10b981;  /* Approval color */
    --warning-orange: #f59e0b; /* Caution color */
    --danger-red: #ef4444;     /* Risk color */
}

🚀 Production Deployment

Backend Deployment (Render/Heroku/AWS)

# Add Procfile
web: gunicorn app:app

# Install gunicorn
pip install gunicorn

# Update requirements.txt
pip freeze > requirements.txt

Frontend Deployment (Netlify/Vercel/GitHub Pages)

  • Update API_BASE_URL in script.js to production backend URL
  • Deploy static files (index.html, styles.css, script.js)

Environment Variables

# Production settings
FLASK_ENV=production
API_KEY=your_api_key_here
CORS_ORIGINS=https://yourdomain.com

📊 Testing

Manual Testing Scenarios

High Approval Profile:

  • Income: ₹100,000
  • Employment: Salaried
  • Credit Score: 800
  • Existing EMI: ₹5,000
  • Requested: ₹500,000
  • Tenure: 5 years
  • Expected: 85%+ approval, Low risk, ~8.5% interest

Medium Risk Profile:

  • Income: ₹40,000
  • Employment: Self-Employed
  • Credit Score: 650
  • Existing EMI: ₹15,000
  • Requested: ₹300,000
  • Tenure: 7 years
  • Expected: 50-70% approval, Medium risk, ~11% interest

High Risk Profile:

  • Income: ₹25,000
  • Employment: Freelancer
  • Credit Score: 550
  • Existing EMI: ₹10,000
  • Requested: ₹400,000
  • Tenure: 10 years
  • Expected: <40% approval, High risk, ~14% interest

🐛 Troubleshooting

Backend Issues

Error: Port 5000 already in use

# Change port in app.py
app.run(debug=True, host='0.0.0.0', port=5001)
# Update API_BASE_URL in script.js

Error: Module not found

# Reinstall dependencies
pip install -r requirements.txt

Frontend Issues

Error: CORS policy error

  • Ensure Flask-CORS is installed
  • Check API_BASE_URL in script.js matches backend

Error: API connection failed

  • Verify backend is running on correct port
  • Check browser console for detailed errors

📈 Future Enhancements

  • Database integration (PostgreSQL/MongoDB)
  • User authentication & loan history
  • Real ML model training on historical data
  • Document upload (income proof, ID verification)
  • Multi-language support
  • Email/SMS notifications
  • Integration with actual credit bureaus
  • Chatbot for financial guidance
  • A/B testing framework
  • Analytics dashboard

📝 License

This project is for educational and demonstration purposes.

Disclaimer: This is an AI-powered tool for informational purposes only. Final loan approval is subject to lender verification, credit checks, and specific terms and conditions. Always consult with financial advisors for major financial decisions.


👥 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Commit with clear messages
  4. Test thoroughly
  5. Submit pull request

📞 Support

For issues, questions, or suggestions:


🙏 Acknowledgments

Built with:

  • Flask (Python web framework)
  • Vanilla JavaScript (no framework dependencies)
  • Modern CSS3 (responsive design)
  • Mathematical algorithms for financial calculations

Made with ❤️ for transparent, ethical AI in fintech

SmartLend.AI - Empowering informed financial decisions through artificial intelligence

About

SmartLend.AI – An AI-powered platform that brings clarity and trust to personal loan decisions. The system analyzes a user’s financial profile in seconds to provide transparent, personalized loan recommendations with complete explanations. Built with secure backend architecture, scalable APIs, and intuitive UI for instant loan analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors