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.
- 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
- 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
- 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
- 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
- Python 3.8 or higher
- pip (Python package manager)
- Modern web browser (Chrome, Firefox, Safari, Edge)
-
Clone the repository
git clone https://github.com/yourusername/news-perspective-meter.git cd news-perspective-meter -
Create a virtual environment
python -m venv venv
-
Activate the virtual environment
Windows:
venv\Scripts\activate
macOS/Linux:
source venv/bin/activate -
Install dependencies
pip install -r requirements.txt
-
Run the application
python app.py
-
Open your browser Navigate to
http://127.0.0.1:5000
- 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
- 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
- NewsAPI - Real-time news headlines (optional)
- Custom REST API - Backend endpoints for data management
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
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=TrueThe 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.
GET /- Main application pageGET /news- Fetch latest headlines (default source)GET /api/headlines/<source>- Fetch headlines from specific source
POST /analyze-sentiment- Analyze article sentimentGET /analyze-sentiment/<text>- Analyze sentiment via GET
GET /reading-history- Retrieve user's reading historyGET /reading-statistics- Get reading pattern statisticsPOST /add-reading-record- Manually add reading record
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 */
}Edit sources.json to add new sources:
{
"sourceName": "Your News Source",
"category": "Left|Center|Right",
"articlesRead": 0,
"country": "International|India"
}- Select a news source from the dropdown
- Click "Load Latest News" to fetch headlines
- Browse through the displayed articles
- Click "Analyze Sentiment" on any headline
- View the AI-powered sentiment analysis
- The analysis is automatically saved to your reading history
- The pie chart shows your reading distribution
- Statistics cards display counts for each category
- The analysis section provides personalized insights
- 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
- Load different news sources
- Analyze various articles
- Check that statistics update correctly
- Verify responsive design on different screen sizes
# 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-statisticspython app.py- Set
FLASK_ENV=production - Use a production WSGI server (e.g., Gunicorn)
- Configure reverse proxy (e.g., Nginx)
- Set up SSL certificates
- Configure environment variables
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- 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
For support, email support@newsperspectivemeter.com or create an issue in the GitHub repository.
- 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