Skip to content

Repository files navigation

📰 TruthLens: AI-Powered Fake News Detector TruthLens is an intelligent web application designed to combat misinformation. It uses a machine learning model to analyze news articles and predict whether they are real or fake, providing a confidence score and additional insights to help users make informed judgments.

✨ Features Real/Fake Prediction: Classifies news content as "Real" or "Fake" using a trained Logistic Regression model.

Confidence Score: Displays the model's confidence percentage for each prediction.

Source Credibility Check: Analyzes URLs to determine if they originate from trusted, unreliable, or unverified domains.

Keyword Analysis: Extracts and displays the top 10 keywords that most influenced the prediction.

Word Cloud Visualization: Generates a word cloud from the article text for a quick visual summary of its content.

Dual Theme: Features a sleek user interface with both Light and Dark mode options.

🛠️ How It Works (ML Workflow) The application follows a standard machine learning pipeline to analyze the text and make predictions.

Data Preprocessing: The input text is cleaned by removing punctuation, links, special characters, and converting it to lowercase.

Feature Extraction: A pre-trained TF-IDF (Term Frequency-Inverse Document Frequency) Vectorizer converts the cleaned text into meaningful numerical vectors.

Model Prediction: A Logistic Regression classifier, trained on a labeled dataset, predicts the probability of the news being real or fake.

Source Check: For URL inputs, the domain is checked against a predefined list of known trusted and unreliable sources.

🚀 Technologies Used Programming Language: Python

Web Framework: Streamlit

Machine Learning: Scikit-learn

Model & Vectorizer Storage: Pickle

Data Visualization: WordCloud & Matplotlib

Text & URL Processing: Regex & tldextract

⚙️ Setup and Installation To run this project locally, follow these steps:

  1. Clone the repository:

Bash

git clone https://github.com/your-username/TruthLens.git cd TruthLens 2. Create and activate a virtual environment:

Bash

For Windows

python -m venv venv venv\Scripts\activate

For macOS/Linux

python3 -m venv venv source venv/bin/activate 3. Install the required dependencies: Create a requirements.txt file with the following content:

pandas scikit-learn streamlit wordcloud matplotlib tldextract notebook Then, install the packages:

Bash

pip install -r requirements.txt 4. Download the Dataset: This model was trained on the "Fake and real news dataset" from Kaggle. Make sure you have the Fake.csv and True.csv files in the root directory of the project.

🏃‍♀️ How to Run the Project The project has two main parts: training the model and running the web application.

Step 1: Train the Model First, you need to run the Jupyter Notebook to train the Logistic Regression model and create the model.pkl and vectorizer.pkl files.

Bash

jupyter notebook train_model.pynb Inside the notebook, run all the cells. This will save the trained model and vectorizer files in your project directory.

Step 2: Launch the Streamlit App Once the model files are generated, you can run the Streamlit application.

Bash

streamlit run app.py This will open the TruthLens web application in your default browser.

📁 Project Structure . ├── 📄 app.py # Main Streamlit application file ├── 📄 Fake.csv # Dataset of fake news articles ├── 📄 True.csv # Dataset of real news articles ├── 📄 requirements.txt # Python dependencies ├── 📓 train_model.pynb # Jupyter notebook for model training ├── 📦 model.pkl # Saved trained model (generated after training) └── 📦 vectorizer.pkl # Saved TF-IDF vectorizer (generated after training) └── 📦 vectorizer.pkl # Saved TF-IDF vectorizer (generated after training)

About

Analyze any news article to check whether it’s Fake or Real using Machine Learning .

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages