AIEngineeringIsFun/ai-news-analyst
AI Media Lens README 🛡️ AI Media Lens: Bias & Sentiment Tracker Project Overview
This project is an intelligent news aggregator built for the Towards AI Academy: Beginner Python for AI Engineering course. It moves beyond simple data retrieval by acting as a media literacy tool, using Large Language Models (LLMs) to analyze top headlines for political bias, sentiment, and fact-framing.
Project Utility
In an era of misinformation, understanding the "slant" of a news story is vital. This app:
- Retrieves real-time data from the
NewsAPI.
- Analyzes the content using a specialized System Prompt in
OpenAI's GPT-3.5-Turbo.
- Identifies political leaning and potential sensationalism.
- Limits token usage to remain cost-effective for the user.
Technical Python Implementation
The project demonstrates several core Python engineering concepts:
• API Orchestration: Uses the requests library to handle HTTP GET requests.
• Secure Credential Handling: API keys are ingested through Gradio's UI.
• Prompt Engineering: Employs a specific System Persona ("Neutral Media Analyst").
• Dynamic UI Rendering: Uses Python string formatting and Markdown.
Setup & API Requirements
To run this application, you will need two API keys:
- NewsAPI Key: Sign up at newsapi.org(https://newsapi.org/).
- OpenAI API Key: Obtain from OpenAI Platform(https://platform.openai.com/).
Troubleshooting
- Invalid API Key Error
• Symptom: The app returns an error message regarding authentication.
• Solution: Ensure keys are copied correctly without extra spaces from NewsAPI and OpenAI.
- Rate Limit Reached
• Symptom: "Rate limit reached" or "429" error.
• Solution: Check your usage limits on the provider dashboards. Free tiers have strict daily/monthly limits.
- "No articles found"
• Symptom: The app runs but the output is empty.
• Solution: Try switching categories (e.g., to "general") or check your internet connection.
- Gradio Interface Issues
• Symptom: Page stuck on "Loading" or local port errors.
• Solution: Refresh your browser. If local, ensure port 7860 is free. On Hugging Face, check that the Space status is "Running".
