Skip to content

Pranamya1833/Perspective-meter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฐ News Perspective Meter

A comprehensive web application that helps users analyze their news consumption patterns and identify potential filter bubbles in their reading habits. The app uses AI-powered sentiment analysis and interactive visualizations to provide personalized insights about media consumption diversity.

News Perspective Meter Python JavaScript Flask License

๐ŸŒŸ Features

๐Ÿ“Š Reading Analytics

  • Real-time tracking of articles read from different political perspectives
  • Interactive pie charts showing reading distribution across Left, Center, and Right sources
  • Statistical insights with detailed breakdowns and percentages
  • Historical tracking of reading patterns over time

๐Ÿค– AI-Powered Analysis

  • Sentiment analysis using DistilBERT model for news articles
  • Automatic categorization of news sources by political leaning
  • Confidence scoring for sentiment analysis results
  • Database storage of all analysis results for trend tracking

๐ŸŽฏ Filter Bubble Detection

  • Personalized analysis of reading habits
  • Filter bubble warnings when over 70% of reading comes from one political category
  • Actionable recommendations for diversifying news consumption
  • Progress tracking towards more balanced reading habits

๐Ÿ“ฑ Modern User Experience

  • Responsive design that works on desktop, tablet, and mobile
  • Clean, modern interface with intuitive navigation
  • Real-time updates as users interact with the application
  • Loading states and error handling for smooth user experience

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • Modern web browser (Chrome, Firefox, Safari, Edge)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/news-perspective-meter.git
    cd news-perspective-meter
  2. Create a virtual environment

    python -m venv venv
  3. Activate the virtual environment

    Windows:

    venv\Scripts\activate

    macOS/Linux:

    source venv/bin/activate
  4. Install dependencies

    pip install -r requirements.txt
  5. Run the application

    python app.py
  6. Open your browser Navigate to http://127.0.0.1:5000

๐Ÿ› ๏ธ Technologies Used

Backend

  • Flask - Web framework for Python
  • SQLite - Lightweight database for storing reading history
  • Transformers - Hugging Face library for AI sentiment analysis
  • Requests - HTTP library for API calls
  • DistilBERT - Pre-trained model for sentiment analysis

Frontend

  • HTML5 - Semantic markup structure
  • CSS3 - Modern styling with CSS Grid and Flexbox
  • JavaScript (ES6+) - Interactive functionality
  • Chart.js - Interactive data visualization
  • Fetch API - Asynchronous HTTP requests

APIs

  • NewsAPI - Real-time news headlines (optional)
  • Custom REST API - Backend endpoints for data management

๐Ÿ“ Project Structure

news-perspective-meter/
โ”œโ”€โ”€ app.py                 # Main Flask application
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ reading_history.db     # SQLite database (created automatically)
โ”œโ”€โ”€ sources.json          # News sources configuration
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ index.html        # Main HTML template
โ”œโ”€โ”€ static/
โ”‚   โ”œโ”€โ”€ style.css         # CSS styles
โ”‚   โ”œโ”€โ”€ script.js         # Original JavaScript
โ”‚   โ””โ”€โ”€ app.js           # Enhanced JavaScript functionality
โ””โ”€โ”€ README.md            # This file

๐Ÿ”ง Configuration

Environment Variables

Create a .env file in the root directory:

# Optional: NewsAPI key for real news data
NEWS_API_KEY=your_newsapi_key_here

# Flask configuration
FLASK_ENV=development
FLASK_DEBUG=True

News Sources

The application includes 45+ news sources across political categories:

  • Left-leaning: The New York Times, CNN, The Guardian, etc.
  • Center: BBC News, Reuters, NPR, Associated Press, etc.
  • Right-leaning: Fox News, The Wall Street Journal, Breitbart, etc.

Sources are configured in sources.json and can be customized as needed.

๐Ÿ“Š API Endpoints

News Endpoints

  • GET / - Main application page
  • GET /news - Fetch latest headlines (default source)
  • GET /api/headlines/<source> - Fetch headlines from specific source

Analysis Endpoints

  • POST /analyze-sentiment - Analyze article sentiment
  • GET /analyze-sentiment/<text> - Analyze sentiment via GET

Data Endpoints

  • GET /reading-history - Retrieve user's reading history
  • GET /reading-statistics - Get reading pattern statistics
  • POST /add-reading-record - Manually add reading record

๐ŸŽจ Customization

Styling

The application uses CSS custom properties for easy theming. Modify the color palette in static/style.css:

:root {
    --primary-color: #2563eb;    /* Main brand color */
    --accent-color: #06b6d4;     /* Accent color */
    --left-color: #ef4444;       /* Left-leaning sources */
    --center-color: #06b6d4;     /* Center sources */
    --right-color: #3b82f6;      /* Right-leaning sources */
}

Adding News Sources

Edit sources.json to add new sources:

{
    "sourceName": "Your News Source",
    "category": "Left|Center|Right",
    "articlesRead": 0,
    "country": "International|India"
}

๐Ÿ” Usage Guide

1. Loading News

  • Select a news source from the dropdown
  • Click "Load Latest News" to fetch headlines
  • Browse through the displayed articles

2. Analyzing Articles

  • Click "Analyze Sentiment" on any headline
  • View the AI-powered sentiment analysis
  • The analysis is automatically saved to your reading history

3. Viewing Analytics

  • The pie chart shows your reading distribution
  • Statistics cards display counts for each category
  • The analysis section provides personalized insights

4. Understanding Recommendations

  • Filter Bubble Warning: Appears when >70% of reading comes from one category
  • Balanced Reading: Praises diverse consumption patterns
  • Actionable Tips: Specific suggestions for improving news diversity

๐Ÿงช Testing

Manual Testing

  1. Load different news sources
  2. Analyze various articles
  3. Check that statistics update correctly
  4. Verify responsive design on different screen sizes

API Testing

# Test sentiment analysis
curl -X POST http://127.0.0.1:5000/analyze-sentiment \
  -H "Content-Type: application/json" \
  -d '{"text": "This is a test article", "store_record": true}'

# Test reading statistics
curl http://127.0.0.1:5000/reading-statistics

๐Ÿš€ Deployment

Local Development

python app.py

Production Deployment

  1. Set FLASK_ENV=production
  2. Use a production WSGI server (e.g., Gunicorn)
  3. Configure reverse proxy (e.g., Nginx)
  4. Set up SSL certificates
  5. Configure environment variables

Docker Deployment

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]

๐Ÿค Contributing

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

๐Ÿ“ License

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

๐Ÿ™ Acknowledgments

  • Hugging Face for the DistilBERT sentiment analysis model
  • Chart.js for interactive data visualization
  • NewsAPI for news data (when API key is provided)
  • Flask community for the excellent web framework

๐Ÿ“ž Support

For support, email support@newsperspectivemeter.com or create an issue in the GitHub repository.

๐Ÿ”ฎ Future Enhancements

  • User authentication and profiles
  • Social sharing of reading insights
  • Advanced analytics and reporting
  • Mobile app development
  • Integration with more news APIs
  • Machine learning for better categorization
  • Export functionality for reading reports

Made with โค๏ธ for promoting media literacy and diverse news consumption

About

This is a website which will give you a different insight on how to view agendas of world issues by the media houses and have a grounded opinion on those

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors