AI-powered fraud detection system that analyzes SMS messages and transaction patterns to prevent digital payment scams before payment approval.
- SMS Scam Detection - NLP-based analysis using TF-IDF and Logistic Regression
- Transaction Risk Analysis - ML-based scoring using Random Forest classifier
- Explainable AI - Clear explanations of fraud indicators and risk factors
- Real-time Analysis - Combined risk assessment with actionable recommendations
- Modern UI - Premium dark mode interface with glassmorphism and animations
- Demo Ready - Pre-loaded examples for instant testing
SafePay AI
βββ Backend (Flask + ML)
β βββ SMS Scam Detector (Logistic Regression + TF-IDF)
β βββ Transaction Analyzer (Random Forest)
β βββ REST API (/analyze endpoint)
βββ Frontend (Vanilla JS)
βββ Interactive fraud detection form
βββ Real-time risk visualization
βββ Detailed explanations
- Python 3.9 or higher
- pip (Python package manager)
-
Clone or navigate to the project directory
cd safepay-ai -
Create a virtual environment
# Windows python -m venv venv venv\Scripts\activate # Linux/Mac python3 -m venv venv source venv/bin/activate
-
Install dependencies
cd backend pip install -r requirements.txt
Before running the application, you need to train the ML models:
# From backend directory
cd training
# Train SMS scam detection model
python train_sms_model.py
# Train transaction risk analysis model
python train_transaction_model.pyExpected output:
- Model accuracy metrics
- Feature importance scores
- Saved model files in
data/trained_models/
-
Start the Flask backend
# From backend directory python app.pyServer will start at:
http://localhost:5000 -
Open the application
- Navigate to
http://localhost:5000in your web browser - The frontend will automatically connect to the backend API
- Navigate to
Click the Quick Examples buttons for instant demos:
- Amount: βΉ50,000
- Receiver: New
- Message: Urgent account block warning with suspicious link
- Expected: High risk, BLOCK recommendation
- Amount: βΉ599
- Receiver: Known
- Message: OTP verification code
- Expected: Low risk, APPROVE recommendation
- Amount: βΉ85,000
- Receiver: New
- Message: Prize/lottery scam
- Expected: High risk, BLOCK recommendation
Analyze a payment for fraud risk.
Request:
{
"amount": 50000,
"is_new_receiver": 1,
"transactions_today": 1,
"message": "URGENT: Your account will be blocked..."
}Response:
{
"risk_level": "High",
"risk_score": 85,
"recommendation": "BLOCK - Manual review required",
"explanation": "Detailed analysis...",
"sms_analysis": {
"is_scam": true,
"confidence": 92.5,
"risk_score": 93,
"indicators": ["Urgency language detected", "Suspicious URL detected"]
},
"transaction_analysis": {
"risk_level": "High Risk",
"risk_score": 100,
"confidence": 88.3,
"risk_factors": ["Very high transaction amount", "New/unknown receiver"]
}
}Health check endpoint.
Response:
{
"status": "healthy",
"message": "SafePay AI is running"
}- Algorithm: Logistic Regression
- Features: TF-IDF vectorization (1000 features, bigrams)
- Training Data: 35 labeled SMS samples
- Accuracy: ~85-90%
- Explainability: Keyword detection, URL analysis, urgency patterns
- Algorithm: Random Forest (100 trees)
- Features: Amount, receiver history, transaction frequency
- Training Data: 50 labeled transactions
- Accuracy: ~85-90%
- Output: 3-class classification (Low/Medium/High risk)
safepay-ai/
βββ backend/
β βββ app.py # Flask application
β βββ config.py # Configuration
β βββ requirements.txt # Python dependencies
β βββ models/
β β βββ sms_detector.py # SMS scam detection
β β βββ transaction_analyzer.py # Transaction risk analysis
β β βββ explainer.py # Model explainability
β βββ data/
β β βββ raw/
β β β βββ sms_dataset.csv # SMS training data
β β β βββ transaction_dataset.csv
β β βββ trained_models/ # Saved .pkl files
β βββ training/
β βββ train_sms_model.py # SMS model trainer
β βββ train_transaction_model.py
βββ frontend/
βββ index.html # Main UI
βββ css/
β βββ styles.css # Premium styling
βββ js/
βββ app.js # Frontend logic
- Demo Only: This is a hackathon project with simulated data
- No Real Integration: No actual UPI/bank APIs are used
- Synthetic Data: All training data is artificially generated
- Not Production Ready: Requires additional security, validation, and testing for real-world use
- Dark mode with vibrant gradients
- Glassmorphism effects
- Smooth animations and transitions
- Responsive design for all devices
- Real-time risk meter visualization
- Interactive demo examples
- Backend: Python, Flask, Flask-CORS
- ML/NLP: scikit-learn, pandas, numpy, nltk
- Frontend: HTML5, CSS3, Vanilla JavaScript
- Design: Custom CSS with modern aesthetics
This is a hackathon demo project for educational purposes.
Built with β€οΈ for hackathon demonstration
Need Help?
- Ensure Python 3.9+ is installed
- Activate virtual environment before running
- Train models before starting the application
- Check that port 5000 is available