Skip to content

AI-powered fake news detector using ML and NLP. Verify news instantly via REST API or Android app. 70%+ accuracy on 10K+ statements.

License

Notifications You must be signed in to change notification settings

w0lzard/SpotLiar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpotLiar Logo

SpotLiar - Fake News Detection

AI-Powered Truth Verification with Machine Learning

Python Flask Android License Docker

Combat misinformation with cutting-edge NLP and Machine Learning

Quick StartFeaturesAPIAndroid AppDocumentation


🌟 Features

🤖 Machine Learning Models

  • 🎯 5 Algorithms: Naive Bayes, Logistic Regression, SVM, SGD, Random Forest
  • 📊 70%+ Accuracy on LIAR benchmark dataset
  • 🔍 Advanced NLP: TF-IDF, N-grams (1-5), Bag of Words
  • Real-time predictions with confidence scores
  • 📈 Model comparison with learning curves

🚀 Production Ready

  • 🐳 Docker containerized for instant deployment
  • 🌐 REST API with Flask backend
  • 📱 Native Android app with Jetpack Compose UI
  • 🔒 Network security and HTTPS ready
  • 📊 Batch prediction support

📊 Data & Analysis

  • 📝 LIAR Dataset: 10,000+ labeled statements
  • 🧹 Preprocessing pipeline: Tokenization, stemming, stopword removal
  • 📈 EDA included: Distribution plots, quality checks
  • 🎨 Visualizations: Confusion matrices, precision-recall curves

🛠️ Developer Experience

  • 📖 Complete documentation with guides
  • 🧪 30+ unit tests for reliability
  • 🔧 One-command setup automation
  • 💻 Multiple interfaces: CLI, API, Mobile
  • 🎯 Type hints and docstrings

🚀 Quick Start

🌐 Live Demo (No Installation Required!)

The API is already hosted and running:

https://spotliar.onrender.com

Test it instantly:

curl https://spotliar.onrender.com/api/health

📱 Android App

Download and install the APK to start verifying news immediately!

  • Works on any network (WiFi/Mobile data)
  • No setup required
  • Instant predictions

⚡ Local Installation

git clone <your-repo-url>
cd Fake_News_Detection-master

chmod +x install.sh && ./install.sh
source .venv/bin/activate
python api_server.py

🐳 Docker

docker-compose up -d
curl http://localhost:5000/api/health

💻 Usage

🖥️ Command Line

python prediction.py

Enter news text: Scientists discover new planet
Result: Real News
Confidence: 87.3%

🌐 REST API

import requests

# Use the live API
response = requests.post('https://spotliar.onrender.com/api/predict',
    json={'text': 'Breaking news: New discovery announced'})

print(response.json())
{
  "success": true,
  "prediction": "Real News",
  "is_fake": false,
  "confidence": 0.873,
  "confidence_percentage": 87.3
}

Live API Base URL: https://spotliar.onrender.com

📱 Android App

  1. Open android/ in Android Studio
  2. Build and run on device
  3. Enter news text and get instant verification

🔌 API Endpoints

Base URL: https://spotliar.onrender.com

Endpoint Method Description
/ GET Root endpoint (200 OK)
/api/health GET Health check
/api/predict POST Predict single news article
/api/batch-predict POST Predict multiple articles
/api/info GET API information

Example Request

# Live API
curl -X POST https://spotliar.onrender.com/api/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "Your news article here"}'

# Local development
curl -X POST http://localhost:5000/api/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "Your news article here"}'

📱 Android App

Android App

Features

  • ✨ Modern Material Design 3 UI
  • 🎨 Jetpack Compose interface
  • 🔄 Real-time predictions
  • 📊 Confidence visualization
  • 🌐 WiFi and USB connectivity

Setup

The app is pre-configured to use the live API at https://spotliar.onrender.com

Build and Install:

cd android
./gradlew assembleDebug
adb install app/build/outputs/apk/debug/app-debug.apk

For local development, update RetrofitClient.kt:

private const val BASE_URL = "http://localhost:5000/"  // or your local IP

See Android Setup Guide and Wireless Setup for details.


🧠 How It Works

1️⃣ Data Preprocessing

Raw Text → Tokenization → Stopword Removal → Stemming → Clean Text

2️⃣ Feature Extraction

Clean Text → TF-IDF Vectorization → N-grams (1-5) → Feature Matrix

3️⃣ Model Training

Feature Matrix → Multiple ML Models → Grid Search → Best Model Selection

4️⃣ Prediction

New Text → Preprocessing → Feature Extraction → Model → Prediction + Confidence

📊 Model Performance

Logistic Regression (Best Model)

  • Accuracy: 70.2%
  • F1 Score: 0.701
  • Precision: 0.68
  • Recall: 0.72
Learning Curve

Model Comparison

Model Accuracy F1 Score Training Time
Logistic Regression 70.2% 0.701 Fast ⚡
Random Forest 66.5% 0.666 Slow 🐌
Naive Bayes 72.3% 0.723 Fastest ⚡⚡
Linear SVM 67.9% 0.679 Medium 🚶
SGD 71.8% 0.719 Fast ⚡

📁 Project Structure

Fake_News_Detection-master/
├── 📄 Core ML Modules
│   ├── DataPrep.py              # Data preprocessing
│   ├── FeatureSelection.py      # Feature extraction
│   ├── classifier.py            # Model training
│   ├── model_trainer.py         # Training utilities
│   ├── prediction.py            # CLI prediction
│   └── api_server.py            # REST API
│
├── 📦 Models & Data
│   ├── final_model.sav          # Trained model
│   ├── train.csv                # Training data
│   ├── test.csv                 # Test data
│   └── liar_dataset/            # Original dataset
│
├── 🐳 Deployment
│   ├── Dockerfile               # Container definition
│   ├── docker-compose.yml       # Orchestration
│   └── .env.example             # Configuration
│
├── 📱 Android App
│   └── android/                 # Jetpack Compose app
│
├── 🧪 Testing
│   └── tests/                   # 30+ unit tests
│
└── 📚 Documentation
    ├── README.md                # This file
    ├── QUICKSTART.md            # Quick start guide
    ├── DEPLOYMENT.md            # Deployment guide
    └── CONTRIBUTING.md          # Contribution guide

🛠️ Tech Stack

Backend

  • Python 3.6+: Core language
  • scikit-learn: ML algorithms
  • NLTK: Natural language processing
  • Flask: REST API framework
  • pandas/numpy: Data manipulation

Frontend

  • Kotlin: Android development
  • Jetpack Compose: Modern UI toolkit
  • Retrofit: HTTP client
  • Material Design 3: UI components

DevOps

  • Docker: Containerization
  • pytest: Testing framework
  • GitHub Actions: CI/CD (optional)

📖 Documentation


🚀 Deployment

☁️ Production (Live)

Currently deployed on Render.com:

Local Development

./start-everything.sh

Deploy Your Own

Render.com (Recommended - Free):

  1. Fork this repository
  2. Connect to Render.com
  3. Deploy with one click
  4. See CLOUD_DEPLOYMENT.md for details

Other Platforms:

  • 🌊 Railway: $5 credit/month
  • Fly.io: Free tier available
  • 🔥 Heroku: $5/month
  • ☁️ AWS/GCP: Full control

See CLOUD_DEPLOYMENT.md for complete deployment guides.


🧪 Testing

pytest
pytest --cov=. --cov-report=html
make test-coverage

Test Coverage: 30+ unit tests covering:

  • ✅ API endpoints
  • ✅ Data preprocessing
  • ✅ Model predictions
  • ✅ Feature extraction

📊 Dataset

LIAR Dataset

  • Source: ACL 2017 Paper by William Yang Wang
  • Size: 12,836 labeled statements
  • Classes: Binary (True/False)
  • Features: Statement text, speaker, context

Data Distribution

  • Training: 10,240 samples
  • Testing: 1,267 samples
  • Validation: 1,284 samples

🎯 Roadmap

Current Version (v1.0)

  • ✅ 5 ML models implemented
  • ✅ REST API with Flask
  • ✅ Android app with Jetpack Compose
  • ✅ Docker containerization
  • ✅ Comprehensive documentation

Future Enhancements

  • 🔮 Deep learning models (BERT, GPT)
  • 🌍 Multi-language support
  • 🎨 Web interface
  • 📊 Real-time dashboard
  • 🔐 User authentication
  • 📈 Model explainability (LIME, SHAP)
  • 🚀 Kubernetes deployment
  • 📱 iOS app

🤝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Quick Contribution Steps

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

📜 License

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


👥 Authors


🙏 Acknowledgments

  • LIAR Dataset: William Yang Wang, ACL 2017
  • scikit-learn: Machine learning library
  • NLTK: Natural language toolkit
  • Flask: Web framework
  • Jetpack Compose: Android UI toolkit

📞 Support


⭐ Star History

If you find this project useful, please consider giving it a star! ⭐


🎯 Made with ❤️ for fighting misinformation

⬆ Back to Top

About

AI-powered fake news detector using ML and NLP. Verify news instantly via REST API or Android app. 70%+ accuracy on 10K+ statements.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published