TrendAnalysis / README.md
lization's picture
Rename README (1).md to README.md
348fd08 verified
|
Raw
History Blame Contribute Delete
2.58 kB
---
title: Trend Longevity Analyser
emoji: πŸ“Š
colorFrom: blue
colorTo: indigo
sdk: gradio
app_file: app.py
pinned: true
---
# πŸ“Š Trend Longevity Analyser
A **RAG-powered trend intelligence tool** that classifies whether any topic is *Early, Rising, at Peak, Declining, or Fading* β€” using live news data.
## How It Works
This tool implements a full 6-step RAG (Retrieval-Augmented Generation) pipeline:
| Step | What Happens |
|------|-------------|
| **1. Fetch** | NewsAPI pulls up to 50 recent articles on your topic |
| **2. Chunk** | LangChain splits articles into overlapping 400-character chunks |
| **3. Embed** | `all-MiniLM-L6-v2` encodes each chunk into a 384-dim vector |
| **4. Store** | ChromaDB holds all vectors in an in-memory collection |
| **5. Retrieve** | Semantic search returns the 10 most relevant chunks |
| **6. Generate** | Gemini analyses the retrieved context and returns a structured trend signal |
## Tech Stack
- **Retrieval:** [ChromaDB](https://www.trychroma.com) (vector store) + [Sentence Transformers](https://sbert.net) (embeddings)
- **Orchestration:** [LangChain](https://langchain.com) text splitting
- **News Data:** [NewsAPI](https://newsapi.org) (free tier)
- **Generation:** [Google Gemini Flash](https://aistudio.google.com) (free tier)
- **UI:** [Gradio](https://gradio.app)
## Setup
### Running Locally
```bash
git clone https://huggingface.co/spaces/lization/trend-longevity-analyser
cd trend-longevity-analyser
pip install -r requirements.txt
export NEWSAPI_KEY=your_key_here
export ANTHROPIC_API_KEY=your_key_here
python app.py
```
### HF Space Secrets
Set `NEWSAPI_KEY` and `GEMINI_API_KEY` as Space Secrets under **Settings β†’ Variables and Secrets**. If not set, users can enter keys directly in the UI.
## Get Your Free API Keys
- **NewsAPI:** [newsapi.org/register](https://newsapi.org/register) β€” free tier, 100 requests/day, last 30 days of articles
- **Google Gemini:** [aistudio.google.com](https://aistudio.google.com) β€” free tier, 1,500 requests/day, no credit card needed
## Why RAG (Not Just a Prompt)?
Instead of passing all 50 articles to Claude (expensive, noisy, hits context limits), the RAG approach:
1. Embeds every chunk as a vector
2. Retrieves only the **10 most semantically relevant chunks** via cosine similarity
3. Passes those to Claude for analysis
This gives more focused, accurate, and cost-efficient results β€” and is directly analogous to production social listening systems used in enterprise contexts.
---
Built by [Sammie Wong](https://linkedin.com/in/sammie-wong)