FakeNews_Detection

Fake News Detector

A Flask-based web app that predicts whether a news article headline is REAL or FAKE from a given URL. It scrapes the page headline, detects and translates non‑English text to English, vectorizes with TF‑IDF, and classifies using Logistic Regression. Authenticated users have their analyzed URLs saved to MySQL.

Table of Contents


Features

Project Workflow

  1. App startup
    • Loads dataset.csv with columns news and label (0 = REAL, 1 = FAKE).
    • Trains an in-memory scikit‑learn pipeline: TfidfVectorizer + LogisticRegression.
    • Initializes MySQL database and tables if missing.
  2. User interaction
    • User opens / and sees a single-page interface.
    • Optional: user signs up or signs in.
  3. URL analysis
    • User submits a news article URL.
    • Server fetches the page (requests) and parses <h1> (BeautifulSoup).
    • Detects headline language (langdetect) and translates to English if needed (deep-translator).
    • Runs the trained model to classify as REAL or FAKE.
  4. Persistence (if authenticated)
    • Saves the submitted URL along with username and full_name into MySQL.
  5. Response
    • Returns JSON with headline, result (“REAL” or “FAKE”), language, and whether it was saved.

Architecture and Modules

Technologies Used

Project Structure

Setup and Installation

  1. Prerequisites
    • Python 3.10+ recommended.
    • MySQL Server accessible from your machine.
    • Windows users can use Command Prompt or PowerShell.
  2. Create and activate a virtual environment
    python -m venv venv
    venv\Scripts\activate
    
  3. Install dependencies
    pip install -r requirements.txt
    
  4. Optional: set a secret key for sessions
    set FLASK_SECRET_KEY=your_very_secret_key
    
  5. Ensure MySQL is running and credentials in app.py match your setup
    • Host, port, user, password, and DB name are defined in app.py.
    • The app will create the database final_project and required tables if they don’t exist.

Running the App

python app.py

API Reference

Example cURL

curl -X POST http://127.0.0.1:4000/detect ^
  -H "Content-Type: application/x-www-form-urlencoded" ^
  --data-urlencode "url=https://example.com/news-article"

Data and Model

Database

Frontend UI

Troubleshooting and Notes