FinGuard AI is a Flask-based financial fraud detection web application that combines an ensemble of machine learning models, SHAP-based explainability, and an LLM-style contextual explanation layer for transaction analysis.
The project includes:
- a user portal for submitting transactions
- an admin dashboard for viewing fraud trends and feature importance
- an ensemble inference pipeline using multiple pretrained models
- SHAP explanations for model transparency
- a Gemini-backed or fallback explanation layer for natural-language summaries
- Real-time fraud scoring for submitted transactions
- Ensemble model consensus across multiple architectures
- SHAP-based feature importance for interpretability
- Session-based admin analytics dashboard
- Model-wise fraud probability breakdown
- Natural-language transaction explanation
- Auto-calculated sender and receiver balances in the UI
- A user submits transaction details from the web interface.
- The Flask backend receives the transaction through
/api/transaction. - The transaction is converted into core numerical features.
- The ML ensemble computes fraud probabilities.
- SHAP is used to identify the most important features.
- A contextual explanation is generated using Gemini if configured, otherwise a local fallback is used.
- The result is returned to the user interface and stored in memory for the admin dashboard.
app.py: Flask routes, session handling, API endpoints, admin aggregationutils/ml_stub.py: model loading, ensemble prediction, SHAP explainabilityutils/llm_stub.py: Gemini integration and fallback explanation logictemplates/: user, admin, and login HTML templatesstatic/: CSS, JavaScript, and UI assetsmodels/: pretrained model artifacts and notebook assets
The runtime ensemble currently loads these model families:
- TCN
- TCN + BiLSTM + Multihead Attention
- CNN + BiLSTM
- LSTM + RF Hybrid
The inference pipeline is built around 5 core numerical transaction features:
amountoldbalanceOrgnewbalanceOrigoldbalanceDestnewbalanceDest
Some models use engineered features and sequence reshaping internally.
- Flask
- Python
- TensorFlow / Keras
- PyTorch
- Scikit-learn
- NumPy
- SHAP
- Joblib
- HTML
- CSS
- JavaScript
- Chart.js
- Google Gemini (
google-generativeai) python-dotenv
It is recommended to run this project in a clean Python 3.11 environment.
Using Conda:
conda create -n finguard python=3.11 -y
conda activate finguardpip install -r requirements.txt
pip install google-generativeaiIf you hit TensorFlow / protobuf issues, install a compatible protobuf version:
pip install protobuf==6.31.1The repository includes a few helper scripts for verification:
test_loader_only.py: checks model loading and a single forward passverify_app.py: runs a dummy transaction through prediction and explanationtest_4_models.py: prints a sample prediction payloaddebug_loader.py: older loader debugging script
Run them with:
python test_loader_only.py
python verify_app.py
python test_4_models.pyFinGuardAI/
├── app.py
├── requirements.txt
├── README.md
├── verify_app.py
├── test_4_models.py
├── test_loader_only.py
├── debug_loader.py
├── models/
├── static/
├── templates/
└── utils/
- Transactions are stored in an in-memory list, so admin analytics reset when the app restarts.
- Admin authentication is currently hard-coded for demonstration.
- Some benchmark numbers shown in the admin UI are static presentation values.
- SHAP must be installed correctly for explainability to work.
- TensorFlow may print oneDNN / CPU optimization logs on startup; these are informational.