Spaces:
Sleeping
Sleeping
File size: 2,583 Bytes
88fe2e0 293b958 88fe2e0 293b958 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ---
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)
|