Skip to content

nihal07g/fake-news-detector-ml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Fake News Detector - AI-Powered News Verification System

Python React Flask License

๐ŸŽฏ Overview

An intelligent web application that uses machine learning to detect fake news articles in real-time. Built with React frontend, Express.js backend, and Python Flask ML API, this system provides accurate predictions with explanatory insights.

โœจ Features

  • Real-time Detection: Instant fake news classification
  • Confidence Scoring: Probability-based predictions
  • Explainable AI: Key indicators influencing decisions
  • Similar Content: Matching with verified real news
  • Responsive Design: Works on all devices
  • Multi-dataset Training: Trained on diverse news datasets

๐Ÿ› ๏ธ Technology Stack

Frontend

  • React 18.2.0 - Modern UI framework
  • Axios - HTTP client for API communication
  • Custom CSS - Responsive styling

Backend

  • Express.js 5.1.0 - Web application framework
  • CORS - Cross-origin resource sharing
  • Node.js - Runtime environment

Machine Learning

  • Python Flask 3.0.3 - ML API framework
  • Scikit-learn 1.5.2 - Machine learning library
  • Multinomial Naive Bayes - Classification algorithm
  • TF-IDF Vectorization - Text feature extraction
  • NumPy & Pandas - Data processing

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   React App     โ”‚    โ”‚  Express.js     โ”‚    โ”‚   Flask ML      โ”‚
โ”‚   (Port 3000)   โ”‚โ”€โ”€โ”€โ–ถโ”‚   (Port 5000)   โ”‚โ”€โ”€โ”€โ–ถโ”‚   (Port 5001)   โ”‚
โ”‚                 โ”‚    โ”‚                 โ”‚    โ”‚                 โ”‚
โ”‚ โ€ข User Interfaceโ”‚    โ”‚ โ€ข API Gateway   โ”‚    โ”‚ โ€ข ML Processing โ”‚
โ”‚ โ€ข Visualizationsโ”‚    โ”‚ โ€ข Request Proxy โ”‚    โ”‚ โ€ข Predictions   โ”‚
โ”‚ โ€ข Form Handling โ”‚    โ”‚ โ€ข CORS Handling โ”‚    โ”‚ โ€ข Explanations  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

Prerequisites

  • Node.js (v14+)
  • Python (v3.8+)
  • Git

Installation

  1. Clone the repository
git clone https://github.com/nihal07g/fake-news-detector-ml.git
cd fake-news-detector-ml
  1. Setup Frontend
cd frontend
npm install
  1. Setup Backend
cd backend
npm install
  1. Setup Python ML API
cd python_api
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
  1. Train the Model
python train_model.py

Running the Application

Start all three services in separate terminals:

# Terminal 1: ML API
cd python_api
python app.py

# Terminal 2: Backend
cd backend
npm start

# Terminal 3: Frontend
cd frontend
npm start

Visit http://localhost:3000 in your browser.

๐Ÿ“Š Model Performance

  • Algorithm: Multinomial Naive Bayes
  • Features: 3,000 TF-IDF features with bi-grams
  • Datasets: WELFake, Custom News, LIAR (optional)
  • Accuracy: Optimized through cross-validation
  • Response Time: < 2 seconds

๐ŸŽฎ Usage

  1. Enter News Text: Paste or type news article content
  2. Click Analyze: Press "Check Authenticity" button
  3. View Results: See prediction with confidence scores
  4. Understand Decision: Review key indicators
  5. Compare Content: View similar real news (if fake detected)

๐Ÿ“ Project Structure

fake-news-detector-ml/
โ”œโ”€โ”€ frontend/                 # React application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.js           # Main component
โ”‚   โ”‚   โ”œโ”€โ”€ App.css          # Styles
โ”‚   โ”‚   โ””โ”€โ”€ index.js         # Entry point
โ”‚   โ”œโ”€โ”€ public/              # Static assets
โ”‚   โ””โ”€โ”€ package.json         # Dependencies
โ”œโ”€โ”€ backend/                 # Express server
โ”‚   โ”œโ”€โ”€ server.js           # API gateway
โ”‚   โ””โ”€โ”€ package.json        # Dependencies
โ”œโ”€โ”€ python_api/             # ML processing
โ”‚   โ”œโ”€โ”€ app.py              # Flask API
โ”‚   โ”œโ”€โ”€ train_model.py      # Model training
โ”‚   โ”œโ”€โ”€ preprocess_*.py     # Data preprocessing
โ”‚   โ”œโ”€โ”€ requirements.txt    # Python deps
โ”‚   โ””โ”€โ”€ *.pkl               # Model artifacts
โ”œโ”€โ”€ .gitignore              # Git ignore rules
โ””โ”€โ”€ README.md               # Documentation

๐Ÿ”ง Configuration

Environment Variables (Optional)

Create .env files for custom configurations:

# Backend (.env)
PORT=5000
PYTHON_API_URL=http://localhost:5001

# Python API (.env)
FLASK_PORT=5001
MODEL_PATH=./model.pkl

๐Ÿค Contributing

  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

๐Ÿ“ˆ Future Enhancements

  • Deep learning models (BERT, LSTM)
  • Multi-language support
  • User authentication
  • Batch processing
  • Advanced visualizations
  • Mobile application
  • Cloud deployment

๐Ÿ› Known Issues

  • Large dataset files not included in repository
  • Model retraining required for optimal performance
  • CORS configuration for production deployment

๐Ÿ“„ License

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

๐Ÿ‘จโ€๐Ÿ’ป Author

Nihal - GitHub

๐Ÿ™ Acknowledgments

  • WELFake Dataset contributors
  • Scikit-learn community
  • React development team
  • Open source community

โญ Star this repository if you found it helpful!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published