Skip to content

labeebnaji/FraudDetect-AI-with-flask-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

FraudDetect AI πŸ›‘οΈ

An intelligent fraud detection system for financial transactions using Artificial Intelligence and Machine Learning.

Python Flask License Status

πŸ“‹ Description

FraudDetect AI is an advanced system that uses Machine Learning algorithms (Random Forest) to analyze financial transactions and detect fraudulent activities with high accuracy. The system provides a comprehensive dashboard with real-time analytics and supports multiple languages.

✨ Features

  • πŸ€– Intelligent Fraud Detection using Random Forest ML Model
  • πŸ“Š Interactive Dashboard with live charts and analytics
  • πŸ“ CSV File Upload & Analysis with automatic processing
  • 🌍 Bilingual Support (Arabic & English) with RTL/LTR
  • πŸŒ“ Dual Theme Mode (Light & Dark)
  • πŸ† Achievements & Points System for user engagement
  • πŸ“± Responsive Design works on all devices
  • πŸ“ˆ Real-time Statistics and threat visualization
  • πŸ” Transaction History with detailed analysis

πŸ› οΈ Technologies Used

Backend

Python Flask SQLite Pandas NumPy Scikit-learn

Frontend

HTML5 CSS3 JavaScript Chart.js

Libraries & Tools

  • Flask 3.0.3 - Web framework
  • Werkzeug 3.0.1 - WSGI utility library
  • Pandas 2.2.2 - Data manipulation and analysis
  • NumPy 1.26.4 - Numerical computing
  • Scikit-learn 1.5.0 - Machine Learning algorithms
  • Chart.js - Interactive charts
  • Font Awesome - Icon library

πŸš€ Installation & Setup

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • Git (optional)

Installation Steps as a local

  1. Clone the repository:
git clone https://github.com/labeebnaji/WebApp-with-AI.git
cd frauddetect-ai/Frauddetect-ai-WebApp
  1. Create a virtual environment (recommended):
python -m venv venv

# Windows
venv\Scripts\activate

# Linux/Mac
source venv/bin/activate
  1. Install required packages:
pip install -r requirements.txt
  1. Set up environment variables:
# Copy the example file
cp .env.example .env

# Edit .env with your settings
  1. Initialize the database:
python -c "from app import app, init_db; init_db()"
  1. Run the application:
python app.py
  1. Open your browser:
http://127.0.0.1:5000

πŸ“ Project Structure

frauddetect-ai/
β”œβ”€β”€ app.py                      # Main application file
β”œβ”€β”€ schema.sql                  # Database schema
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ random_forest_model.pkl     # ML model (trained)
β”œβ”€β”€ .env.example               # Environment variables template
β”œβ”€β”€ .gitignore                 # Git ignore rules
β”œβ”€β”€ LICENSE                    # MIT License
β”œβ”€β”€ README.md                  # Project documentation
β”œβ”€β”€ static/                    # Static files
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css         # Main stylesheet
β”‚   └── js/
β”‚       └── main.js           # JavaScript functionality
β”œβ”€β”€ templates/                 # HTML templates
β”‚   β”œβ”€β”€ base.html             # Base template
β”‚   β”œβ”€β”€ index.html            # Dashboard page
β”‚   β”œβ”€β”€ upload.html           # File upload page
β”‚   β”œβ”€β”€ alerts.html           # Alerts & analytics page
β”‚   β”œβ”€β”€ profile.html          # User profile page
β”‚   β”œβ”€β”€ achievements.html     # Achievements page
β”‚   └── errors/               # Error pages
β”‚       β”œβ”€β”€ 404.html
β”‚       └── 500.html
└── translations/              # Language files
    β”œβ”€β”€ ar.json               # Arabic translations
    └── en.json               # English translations

πŸ“Š Usage

1. Upload CSV File

  • Navigate to "Upload Data" page
  • Upload a CSV file containing transactions
  • Click "Run Model" to analyze

2. View Results

  • Transactions are automatically analyzed
  • Fraudulent transactions appear in red
  • Safe transactions appear in green
  • View detailed statistics on the dashboard

3. Monitor Statistics

  • Dashboard displays comprehensive statistics
  • Interactive charts for threat visualization
  • Overall security score indicator

πŸ“ CSV File Format

The CSV file must contain the following columns:

cc_num,category,amt,zip,lat,long,city_pop,merch_lat,merch_long,trans_day,trans_month,trans_year,trans_hour,trans_minute

Example:

cc_num,category,amt,zip,lat,long,city_pop,merch_lat,merch_long,trans_day,trans_month,trans_year,trans_hour,trans_minute
4532123456789012,grocery,45.50,12345,40.7128,-74.0060,8000000,40.7580,-73.9855,15,1,2025,14,30
6011987654321098,gas_transport,75.20,54321,34.0522,-118.2437,4000000,34.0689,-118.4452,16,1,2025,9,15

Column Descriptions:

  • cc_num: Credit card number
  • category: Transaction category (grocery, gas_transport, etc.)
  • amt: Transaction amount
  • zip: ZIP code
  • lat, long: Customer location coordinates
  • city_pop: City population
  • merch_lat, merch_long: Merchant location coordinates
  • trans_day, trans_month, trans_year: Transaction date
  • trans_hour, trans_minute: Transaction time

🎯 Features Overview

Dashboard

  • Real-time threat detection statistics
  • Monthly comparison charts
  • Security score indicator
  • Interactive data visualization

Upload & Analysis

  • Drag & drop file upload
  • Automatic CSV validation
  • Batch transaction processing
  • Instant fraud detection results

Alerts & Analytics

  • Comprehensive transaction history
  • Fraud/Safe transaction filtering
  • Detailed transaction information
  • Export capabilities (coming soon)

User Profile

  • Personal information management
  • Social media links
  • Activity tracking
  • Achievement progress

Achievements System

  • Threat Finder: Discover your first security threat
  • Security Expert: Discover 50+ security threats
  • Cybersecurity Master: Master all security modules

βš™οΈ Configuration

Environment Variables (.env)

FLASK_APP=app.py
FLASK_ENV=development
SECRET_KEY=your-secret-key-here
DATABASE_URL=frauddetect.db
DEBUG=True
HOST=0.0.0.0
PORT=5000
MAX_CONTENT_LENGTH=16777216

πŸ”’ Security Notes

⚠️ Important: This system is for educational and development purposes. Before using in production:

  1. βœ… Enable SECRET_KEY in app.py
  2. βœ… Implement user authentication system
  3. βœ… Encrypt credit card numbers
  4. βœ… Add CSRF Protection
  5. βœ… Use HTTPS
  6. βœ… Add Rate Limiting
  7. βœ… Implement proper logging
  8. βœ… Use production-grade database (PostgreSQL/MySQL)
  9. βœ… Add input validation and sanitization
  10. βœ… Implement backup mechanisms

πŸš€ Deployment

For Production:

  1. Use a production WSGI server:
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 app:app
  1. Set environment to production:
FLASK_ENV=production
DEBUG=False
  1. Use a reverse proxy (Nginx/Apache)

  2. Enable HTTPS with SSL certificate

  3. Use a production database

πŸ§ͺ Testing

# Run tests (when implemented)
python -m pytest tests/

# Check code coverage
python -m pytest --cov=app tests/

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Authors

  • Labeeb Al Baqeri - Initial work

πŸ™ Acknowledgments

  • Flask documentation and community
  • Scikit-learn for ML algorithms
  • Chart.js for beautiful visualizations
  • Font Awesome for icons
  • All contributors and supporters

πŸ“§ Contact

For questions or suggestions, please open an issue on GitHub.

πŸ“Έ Screenshots

Dashboard

Dashboard

Upload Page

Upload

Results

Results


Made with ❀️ using Flask & Python

⭐ Star this repo if you find it useful!

About

FraudDetect-AI-with flask app - WebApp with AI models

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published