Skip to content

imadnan4/FactRadar

Repository files navigation

FactRadar - AI-Powered Fake News Detection

FactRadar is an advanced AI-powered application designed to detect fake news and misinformation in text content. It uses multiple machine learning models and AI verification to provide accurate analysis of news articles, social media posts, and other text sources.

πŸ—οΈ Project Structure

FactRadar/
β”œβ”€β”€ πŸ“ app/                          # Next.js app directory
β”‚   β”œβ”€β”€ globals.css                 # Global styles
β”‚   β”œβ”€β”€ layout.tsx                  # Root layout
β”‚   └── page.tsx                    # Main application page
β”œβ”€β”€ πŸ“ backend/                     # Python Flask backend
β”‚   β”œβ”€β”€ app.py                      # Main Flask application
β”‚   β”œβ”€β”€ requirements.txt            # Python dependencies
β”‚   β”œβ”€β”€ πŸ“ models/                  # ML models directory
β”‚   β”‚   β”œβ”€β”€ best_model_gradient_boosting.pkl
β”‚   β”‚   β”œβ”€β”€ best_model_metadata.json
β”‚   β”‚   β”œβ”€β”€ cnn_model.h5
β”‚   β”‚   β”œβ”€β”€ lstm_model.h5
β”‚   β”‚   └── tfidf_vectorizer_full.pkl
β”œβ”€β”€ πŸ“ components/                  # React components
β”‚   β”œβ”€β”€ FakeNewsDetector.tsx        # Main detection component
β”‚   β”œβ”€β”€ theme-provider.tsx          # Theme management
β”‚   β”œβ”€β”€ theme-switcher.tsx          # Theme toggle component
β”‚   β”œβ”€β”€ theme-toggle.tsx            # Alternative theme toggle
β”‚   └── πŸ“ ui/                      # Shadcn/ui components
β”œβ”€β”€ πŸ“ fake-and-real-news-dataset/   # Training datasets
β”‚   β”œβ”€β”€ Fake.csv
β”‚   └── True.csv
β”œβ”€β”€ πŸ“ hooks/                       # Custom React hooks
β”‚   β”œβ”€β”€ use-mobile.tsx
β”‚   β”œβ”€β”€ use-toast.ts
β”‚   └── useFactCheck.ts             # Main fact-checking hook
β”œβ”€β”€ πŸ“ lib/                        # Utility libraries
β”‚   β”œβ”€β”€ formatReasoning.tsx        # Reasoning formatting utilities
β”‚   β”œβ”€β”€ openrouter.ts              # OpenRouter API client
β”‚   └── utils.ts                   # General utilities
β”œβ”€β”€ πŸ“ public/                     # Static assets
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ placeholder-logo.png
β”‚   β”œβ”€β”€ placeholder-logo.svg
β”‚   β”œβ”€β”€ placeholder-user.jpg
β”‚   β”œβ”€β”€ placeholder.jpg
β”‚   β”œβ”€β”€ placeholder.svg
β”‚   β”œβ”€β”€ script.js
β”‚   β”œβ”€β”€ style.css
β”‚   └── πŸ“ models/                 # Frontend ML models
β”‚       β”œβ”€β”€ preprocessing_config.json
β”‚       └──  vocabulary.json
β”œβ”€β”€ πŸ“ src/                        # Source files
β”‚   β”œβ”€β”€ prediction.js
β”‚   β”œβ”€β”€ preprocessing.js
β”‚   └── utils.js
β”œβ”€β”€ πŸ“ styles/                     # Additional styles
β”‚   └── globals.css

β”œβ”€β”€ πŸ“ training/                   # Model training infrastructure
β”‚   β”œβ”€β”€ πŸ“ data/
β”‚   β”‚   β”œβ”€β”€ πŸ“ processed/
β”‚   β”‚   β”‚   β”œβ”€β”€ feature_summary.json
β”‚   β”‚   β”‚   β”œβ”€β”€ fully_processed_dataset.csv
β”‚   β”‚   β”‚   β”œβ”€β”€ real_dataset_processed.csv
β”‚   β”‚   β”‚   β”œβ”€β”€ tfidf_vectorizer_full.pkl
β”‚   β”‚   β”‚   └── πŸ“ models/
β”‚   β”‚   β”‚       β”œβ”€β”€ best_model_gradient_boosting.pkl
β”‚   β”‚   β”‚       β”œβ”€β”€ best_model_metadata.json
β”‚   β”‚   β”‚       β”œβ”€β”€ cnn_model.h5
β”‚   β”‚   β”‚       β”œβ”€β”€ keras_tokenizer.pkl
β”‚   β”‚   β”‚       β”œβ”€β”€ lstm_model.h5
β”‚   β”‚   β”‚       └── πŸ“ version 2/
β”‚   β”‚   └── πŸ“ raw/
β”‚   β”œβ”€β”€ πŸ“ notebooks/
β”‚   β”‚   β”œβ”€β”€ data_exploration.ipynb
β”‚   β”‚   β”œβ”€β”€ model_training.ipynb
β”‚   β”‚   └── preprocessing.ipynb
β”‚   └── πŸ“ scripts/
β”‚       β”œβ”€β”€ load_real_datasets.py
β”‚       β”œβ”€β”€ quick_data_check.py
β”‚       β”œβ”€β”€ setup_project.py
β”‚       └── test_notebook_fix.py
β”œβ”€β”€ πŸ“„ .env.example                # Environment variables template
β”œβ”€β”€ πŸ“„ .gitignore                  # Git ignore rules
β”œβ”€β”€ πŸ“„ CHANGELOG.md                # Version history
β”œβ”€β”€ πŸ“„ components.json             # Shadcn/ui configuration
β”œβ”€β”€ πŸ“„ README.md                   # This file
β”œβ”€β”€ πŸ“„ netlify.toml                # Netlify deployment config
β”œβ”€β”€ πŸ“„ next.config.mjs             # Next.js configuration
β”œβ”€β”€ πŸ“„ package.json                # Frontend dependencies
β”œβ”€β”€ πŸ“„ pnpm-lock.yaml              # Package lock file
β”œβ”€β”€ πŸ“„ postcss.config.mjs          # PostCSS configuration
β”œβ”€β”€ πŸ“„ requirements.txt            # Python dependencies
β”œβ”€β”€ πŸ“„ tailwind.config.ts          # Tailwind CSS configuration
└── πŸ“„ tsconfig.json               # TypeScript configuration

✨ Features

  • Multiple Model Support: Choose between different AI models for analysis:
    • Gradient Boosting (traditional ML)
    • LSTM (deep learning)
    • CNN (deep learning)
  • Real-time Analysis: Get instant feedback on the authenticity of text content
  • AI Cross-Verification: Uses OpenRouter Mistral AI to provide additional verification
  • Detailed Reasoning: View the AI's reasoning process for more transparent results
  • Modern UI: Clean, responsive interface with glass-morphism design elements
  • Privacy-First: Analysis happens directly in your browser

πŸŽ₯ Demo

Check out the live demo on X (formerly Twitter): FactRadar Demo

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • Python (v3.8 or higher)
  • pip (for Python package management)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/factradar.git
    cd factradar
  2. Install frontend dependencies:

    npm install --legacy-peer-deps
  3. Install backend dependencies:

    cd backend
    pip install -r requirements.txt
  4. Set up environment variables: Copy .env.example to .env.local and fill in your OpenRouter API key:

    cp .env.example .env.local
    # Edit .env.local with your actual API key

Running the Application

  1. Start the backend server (Terminal 1):

    cd backend
    python app.py
  2. Start the frontend (Terminal 2):

    npm run dev
  3. Open your browser and navigate to http://localhost:3000

🧠 How It Works

FactRadar uses a combination of traditional machine learning and deep learning techniques to analyze text content:

  1. Text Preprocessing: Cleans and normalizes the input text
  2. Feature Extraction: Extracts relevant features from the text
  3. Model Analysis: Processes the features through the selected AI model
  4. AI Cross-Verification: Sends the text to OpenRouter Mistral for additional verification
  5. Result Presentation: Displays the analysis results with confidence scores

πŸ€– Models

Gradient Boosting

Traditional ML model with high accuracy on structured features. Uses TF-IDF vectorization and engineered features.

Performance Metrics:

  • Test Accuracy: 99.67%
  • Test Precision: 100%
  • Test Recall: 99.33%
  • Test F1-Score: 99.67%

LSTM (Long Short-Term Memory)

Deep learning model good at capturing sequential patterns in text data.

CNN (Convolutional Neural Network)

Deep learning model effective at capturing local patterns and features in text.

πŸ› οΈ Tech Stack

Frontend

  • Framework: Next.js 15 with React 19
  • Styling: Tailwind CSS + Shadcn/ui
  • Language: TypeScript
  • State Management: React Hooks
  • HTTP Client: Fetch API

Backend

  • Framework: Flask (Python)
  • ML Libraries: scikit-learn, TensorFlow, XGBoost
  • NLP: NLTK
  • API: RESTful endpoints

Machine Learning

  • Traditional ML: Gradient Boosting, XGBoost
  • Deep Learning: LSTM, CNN
  • Feature Engineering: TF-IDF, sentiment analysis, linguistic features

πŸ“Š Dataset Information

The models were trained on:

  • Total Samples: 3,998 (1,999 real + 1,999 fake)
  • Training Set: 2,798 samples
  • Validation Set: 600 samples
  • Test Set: 600 samples
  • Features: 10,012 total features (10,000 TF-IDF + 12 engineered)

πŸ”§ Development

Project Scripts

Frontend:

npm run dev          # Start development server
npm run build        # Build for production
npm run start        # Start production server
npm run lint         # Run ESLint

Backend:

python app.py        # Start Flask server

Environment Variables

Create a .env.local file with:

NEXT_PUBLIC_OPENROUTER_API_KEY=your_openrouter_api_key_here
BACKEND_URL=http://localhost:5000
NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Guidelines

  1. Follow the existing code style
  2. Add tests for new features
  3. Update documentation as needed
  4. Ensure all tests pass before submitting

πŸ“„ License

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

πŸ™ Acknowledgments

  • OpenRouter for providing AI verification capabilities
  • Shadcn/ui for the beautiful UI components
  • The open-source community for the amazing tools and libraries

πŸ“ž Support

For support, please open an issue on GitHub or contact the development team.

About

The Purpose of the to find Fake News to avoid conflict that arise due to Fake News.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published