Skip to content

Latest commit

Β 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 AI News Intelligence Dashboard

A full-stack market intelligence platform that harvests real-time global news, structures it via an automated ETL pipeline, and surfaces insights through a RAG-powered AI assistant and an interactive Streamlit dashboard.

Python Streamlit Google Gemini SQLite


πŸ“– Overview

AI News Intelligence is a business intelligence application built around a three-stage architecture: ingest β†’ analyse β†’ surface. It continuously harvests US headlines from NewsAPI, cleans and deduplicates them into a SQLite database, and then exposes them through two AI-powered engines:

  1. RAG Assistant β€” a senior-analyst LLM agent (gemini-2.5-flash) that answers natural-language queries grounded exclusively in historical database context, with strict hallucination safeguards.
  2. Delta Engine β€” a narrative drift detector that classifies topics as emerging, persistent, or fading by comparing any two point-in-time report snapshots.

All insights are surfaced through a premium, custom-styled Streamlit dashboard with interactive charts, metric cards, and topic frequency timelines.


🎯 Who Is It For & What Problem Does It Solve?

In an era of constant news cycles, staying informed without drowning in noise is a genuine challenge β€” especially for professionals who need to act on information, not just consume it.

The Problem

Pain Point Reality Without This Tool
πŸ“° Information overload Dozens of sources publish hundreds of articles daily. Reading everything is impossible.
⏳ Time-consuming research Manually scanning headlines, cross-referencing sources, and spotting trends takes hours.
🧩 No narrative memory It's hard to recall what topics dominated last week vs. today β€” context gets lost.
πŸ” No natural-language access Standard news platforms don't let you ask questions about what they've reported.
πŸ“‰ Missed trend signals Slow-building or fading stories fly under the radar without systematic tracking.

How This Application Helps

AI News Intelligence is built for analysts, researchers, students, and curious professionals who want a single, intelligent platform to:

  • βœ… Save hours of daily reading β€” the ETL pipeline collects and deduplicates headlines automatically, so you only see what's new and relevant.
  • βœ… Get the big picture instantly β€” AI-generated summaries distil dozens of articles into concise, actionable intelligence in seconds.
  • βœ… Ask questions in plain English β€” instead of searching through articles, simply ask "What has been the biggest economic story this week?" and get a grounded answer drawn from real stored data.
  • βœ… Track how narratives evolve over time β€” the Delta Engine automatically flags which topics are rising, holding steady, or disappearing between any two moments in history, giving you an early-warning system for shifting conversations.
  • βœ… Trust the answers you get β€” unlike generic chatbots, the RAG engine is strictly prohibited from speculating beyond what's actually in the database, eliminating hallucination risk.

In short: this tool turns a chaotic news feed into a structured, queryable, time-aware intelligence archive β€” so you stay informed with minimal effort and maximum confidence.


✨ Key Features

Feature Description
πŸ”„ Automated ETL Pipeline Fetches, sanitises, deduplicates, and loads raw headlines into SQLite on demand
πŸ” Vector Semantic Search NumPy cosine-similarity retrieval against Gemini gemini-embedding-001 embeddings
πŸ€– RAG Intelligence Engine Context-grounded LLM responses with no hallucination beyond stored data
πŸ“Š Delta Engine Point-in-time report comparison to detect emerging, persistent, and fading narratives
πŸ“ˆ Interactive Dashboard Streamlit UI with topic trends, metric cards, and filterable report history
πŸ›‘οΈ Resilient API Handling Quota guards and safety logic for high-volume Gemini API calls

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         AI News Intelligence                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚              ETL Pipeline (app/pipeline.py)     β”‚
         β”‚                                                 β”‚
         β”‚  [NewsAPI] ──► fetch_news ──► clean_data ──► SQLite DB         β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                  β”‚                  β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ Embeddings Engineβ”‚ β”‚  Report Builderβ”‚ β”‚   Delta Engine     β”‚
    β”‚ (embeddings.py)  β”‚ β”‚(report_builder)β”‚ β”‚ (report_compare)  β”‚
    β”‚ gemini-embed-001 β”‚ β”‚ gemini-2.5-    β”‚ β”‚ Topic drift &      β”‚
    β”‚ + NumPy cosine   β”‚ β”‚ flash + topics β”‚ β”‚ narrative shifts   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                  β”‚                  β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    RAG Assistant (rag.py)   β”‚
                    β”‚  gemini-2.5-flash Β· context β”‚
                    β”‚  grounded Β· no hallucinationβ”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Streamlit Dashboard        β”‚
                    β”‚  (frontend/dashboard.py)    β”‚
                    β”‚  Charts Β· Metrics Β· Search  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Technology Stack

Layer Technology Purpose
AI / LLM Google Gemini gemini-2.5-flash Report generation, RAG responses
Embeddings Google gemini-embedding-001 + REST Vector creation, semantic memory
Vector Search NumPy (cosine similarity) Retrieval against stored embeddings
Data Ingestion NewsAPI + requests Live US headline extraction
Data Processing Pandas, Python re Cleaning, deduplication, normalisation
Database SQLite3 Persistent storage with safe schema migrations
Frontend Streamlit + Custom CSS Interactive dashboard and analytics UI
Config & Secrets python-dotenv Environment variable isolation
Logging Python logging Structured runtime diagnostics

πŸ“‚ Project Structure

ai-news-intelligence/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py              # CLI entry point for manual pipeline runs
β”‚   β”œβ”€β”€ pipeline.py          # ETL orchestrator (Extract β†’ Transform β†’ Load)
β”‚   β”œβ”€β”€ fetch_news.py        # NewsAPI integration
β”‚   β”œβ”€β”€ clean_data.py        # Article sanitisation & deduplication
β”‚   β”œβ”€β”€ database.py          # SQLite schema, migrations, and CRUD operations
β”‚   β”œβ”€β”€ embeddings.py        # Gemini embedding generation & storage
β”‚   β”œβ”€β”€ semantic_search.py   # Cosine similarity retrieval
β”‚   β”œβ”€β”€ rag.py               # RAG response generation (Gemini)
β”‚   β”œβ”€β”€ ai_summary.py        # AI-powered news summary engine
β”‚   β”œβ”€β”€ report_builder.py    # Full intelligence report assembly
β”‚   β”œβ”€β”€ report_compare.py    # Delta Engine β€” narrative drift detection
β”‚   β”œβ”€β”€ topic_analytics.py   # Topic frequency & trend analysis
β”‚   β”œβ”€β”€ queries.py           # All database query functions
β”‚   β”œβ”€β”€ config.py            # Environment variable loading
β”‚   └── logger.py            # Logger factory
β”œβ”€β”€ frontend/
β”‚   └── dashboard.py         # Streamlit dashboard (all UI logic)
β”œβ”€β”€ data/
β”‚   └── news.db              # SQLite database (auto-created)
β”œβ”€β”€ logs/                    # Runtime log files
β”œβ”€β”€ .streamlit/              # Streamlit theme configuration
β”œβ”€β”€ requirements.txt
└── .env                     # API keys (not committed)

πŸš€ Getting Started

Prerequisites

1. Clone the repository

git clone https://github.com/your-username/ai-news-intelligence.git
cd ai-news-intelligence

2. Create and activate a virtual environment

python -m venv venv
source venv/bin/activate      # macOS / Linux
# venv\Scripts\activate       # Windows

3. Install dependencies

pip install -r requirements.txt

4. Configure environment variables

Create a .env file in the project root:

NEWS_API_KEY=your_newsapi_key_here
GEMINI_API_KEY=your_gemini_api_key_here

5. Run the ETL pipeline (populate the database)

python -m app.main

Expected output:

Starting manual pipeline execution...
βœ… Success! Fetched: 38 | Cleaned: 35 | Newly Inserted: 35

6. Launch the dashboard

streamlit run frontend/dashboard.py

Navigate to http://localhost:8501 in your browser.


πŸ”‘ Core Modules

app/pipeline.py β€” ETL Orchestrator

Coordinates the full ingestion cycle: initialises the database schema, fetches raw articles from NewsAPI, applies cleaning and deduplication, and inserts new records. Returns execution metrics (raw_count, cleaned_count, inserted_count).

app/rag.py β€” RAG Intelligence Engine

Takes a user query and a list of semantically retrieved articles, constructs a strict prompt that forbids the LLM from reasoning beyond the provided context, and returns a grounded, citation-safe answer via gemini-2.5-flash.

app/embeddings.py β€” Vector Memory

Calls the gemini-embedding-001 REST endpoint to generate 768-dimensional embeddings for each stored summary, enabling persistent semantic memory independent of the Gemini Python SDK.

app/report_compare.py β€” Delta Engine

Parses two historical report snapshots and computes the narrative drift: which topics/sources are newly added, which have disappeared, and which persist β€” enabling trend-over-time business analysis.

frontend/dashboard.py β€” Streamlit Dashboard

A ~14k-line premium UI featuring source filters, date range selectors, topic frequency timelines, a live RAG chat interface, and a Delta Engine comparison panel β€” all injected with custom CSS for a polished look.


πŸ“Š Database Schema

-- Raw ingested headlines
CREATE TABLE articles (
    id           INTEGER PRIMARY KEY AUTOINCREMENT,
    title        TEXT    NOT NULL,
    source       TEXT,
    published_at TEXT,
    url          TEXT    UNIQUE NOT NULL
);

-- AI-generated summaries with topic metadata and embeddings
CREATE TABLE summaries (
    id           INTEGER PRIMARY KEY AUTOINCREMENT,
    summary_text TEXT    NOT NULL,
    topics       TEXT,           -- structured topic:count pairs
    source_filter TEXT,
    article_limit INTEGER,
    embedding    TEXT,           -- serialised float vector (JSON)
    created_at   TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Full intelligence reports (point-in-time snapshots)
CREATE TABLE reports (
    id                 INTEGER PRIMARY KEY AUTOINCREMENT,
    report_timestamp   TEXT,
    total_articles     INTEGER,
    displayed_articles INTEGER,
    what_matters_now   TEXT,
    summary_text       TEXT,
    dominant_topics    TEXT,
    top_sources        TEXT,
    source_filter      TEXT,
    article_limit      INTEGER,
    created_at         TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

πŸ”’ Security Notes

  • API keys are loaded exclusively from .env via python-dotenv and are never hardcoded.
  • .env is listed in .gitignore β€” do not commit it.
  • The RAG prompt enforces strict context boundaries to prevent the LLM from disclosing information outside the stored dataset.

πŸ“„ License

This project is licensed under the MIT License.

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages