A local-first intelligence platform that maps the emotional landscape of social media discourse
Transform unstructured social noise into structured, actionable psychological insights
Social media analysis faces a dual challenge: Data Velocity and Semantic Ambiguity.
| Problem | Traditional Approach | Reality |
|---|---|---|
| Shallow Analysis | Count keywords & hashtags | Fails to capture why a topic is trending |
| Binary Sentiment | Positive vs Negative | Misses psychological nuance (Fear vs Anger vs Disgust) |
| Data Pollution | Manual filtering | Bots, duplicates, and sarcasm break classifiers |
TweetScape is a full-stack intelligence engine that replaces static charts with a "Tug of War" Physics Simulationโphysically pulling conflicting opinions apart in real-time to visualize public discourse polarization.
The system orchestrates a modular AI pipeline:
- Discriminative Models (RoBERTa, UMAP) handle high-speed clustering and emotion detection
- Generative Agent (Gemma 3 via Ollama) autonomously expands queries and summarizes narratives
- Query Expansion: Gemma 3 (4B) via Ollama generates related search queries for broader coverage
- Contextual Summarization: LLM synthesizes cluster content into executive summaries
- Local Inference: Zero API costsโruns entirely on your machine
- Semantic Embeddings:
all-MiniLM-L6-v2for high-quality text representations - 7-Class Emotion Detection: Joy, Anger, Fear, Disgust, Sadness, Surprise, Neutral using
distilroberta-base - Sentiment Analysis:
twitter-roberta-base-sentimentwith continuous -1 to +1 scoring - Topic Extraction: KeyBERT identifies key themes (e.g., "Pricing", "UX", "Support")
- UMAP Projection: Preserves global semantic structure in 2D visualization
- "Tug of War" Layout: Custom D3.js force simulation
- X-axis: Sentiment polarity (Negative โ โ Positive)
- Color: Emotional driver (7 distinct colors)
- Glow effects for strong sentiments
- Live Metrics: Real-time Polarization Score (0-1), sentiment distribution
- Smart Deduplication: Removes exact and near-duplicates (normalized text matching)
- Bot Filtering: Surface-level spam detection
- Transparency: Quality metrics exposed in UI ("15% duplicates removed")
graph TD
User["๐ User Query"] -->|Topic| API[FastAPI Backend]
subgraph Orchestration
API -->|Expand Query| Agent["๐ค Gemma 3 Agent"]
Agent -->|5 Related Queries| Scraper
end
subgraph Data Collection
Scraper["๐ Playwright Scraper"] -->|Raw Tweets| Dedup[Deduplication]
end
subgraph Intelligence Pipeline
Dedup -->|Clean Data| Embed["๐ Sentence Transformers"]
Embed -->|Embeddings| UMAP["UMAP Reduction"]
Embed -->|Text| Sentiment["RoBERTa Sentiment"]
Embed -->|Text| Emotion["RoBERTa Emotion"]
Embed -->|Text| Topics["KeyBERT Topics"]
end
subgraph Visualization
UMAP -->|Coordinates| React["โ๏ธ React Frontend"]
Sentiment -->|Scores| React
Emotion -->|Labels| React
Topics -->|Keywords| React
React -->|D3.js| Force["Force Simulation"]
end
Agent -->|Summarize| Summary["๐ AI Summary"]
Summary --> React
| Technology | Purpose |
|---|---|
| React 19 (Vite) | Component-based UI architecture |
| D3.js | Custom force simulation & physics-based visualization |
| Framer Motion | Smooth animations and transitions |
| Plotly.js | Additional chart components |
| Technology | Purpose |
|---|---|
| FastAPI | High-performance async API framework |
| Playwright | Headless browser automation for Twitter scraping |
| Pydantic | Request/response validation |
| Uvicorn | ASGI production server |
| Model | Purpose |
|---|---|
| Ollama + Gemma 3 (4B) | Local LLM for query expansion & summarization |
| all-MiniLM-L6-v2 | Sentence embeddings |
| cardiffnlp/twitter-roberta-base-sentiment | Sentiment analysis |
| j-hartmann/emotion-english-distilroberta-base | 7-class emotion detection |
| KeyBERT | Topic/keyword extraction |
| UMAP | Dimensionality reduction |
- Python 3.10+
- Node.js 18+
- Ollama (for AI agent features)
git clone https://github.com/SuyeshJadhav/tweetscape.git
cd tweetscapecd backend
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install Playwright browser
playwright install chromium
# Start the server
uvicorn main:app --reloadcd frontend
# Install dependencies
npm install
# Start development server
npm run dev# Pull the Gemma 3 model for the agent
ollama pull gemma3:4b
# Verify Ollama is running
curl http://localhost:11434/api/tags- Navigate to
http://localhost:3000 - Enter a search topic (e.g., "iPhone 16")
- Wait for scraping + analysis pipeline
- Explore the Tug of War visualization!
tweetscape/
โโโ backend/
โ โโโ main.py # FastAPI app entrypoint
โ โโโ config.py # Centralized configuration
โ โโโ routes/
โ โ โโโ cluster.py # /api endpoints for clustering
โ โ โโโ agent.py # /agent endpoints for AI features
โ โโโ services/
โ โโโ scraper.py # Playwright Twitter scraper
โ โโโ pipeline.py # Main processing orchestration
โ โโโ analysis.py # Sentiment, emotion, topic extraction
โ โโโ clustering.py # UMAP, embeddings, clustering
โ โโโ agent.py # Query expansion & summarization logic
โ โโโ ollama_client.py # Direct Ollama HTTP client
โโโ frontend/
โ โโโ src/
โ โ โโโ App.jsx # Main application component
โ โ โโโ components/
โ โ โ โโโ ClusterMap.jsx # D3.js Tug of War visualization
โ โ โ โโโ SearchBar.jsx # Topic input
โ โ โ โโโ TweetList.jsx # Tweet display
โ โ โ โโโ Loading.jsx # Loading states
โ โ โโโ api/
โ โ โโโ client.js # Backend API client
โ โโโ index.html
โโโ data/ # Generated tweet & cluster data
- Pagination: Server-side pagination for 10k+ tweet datasets
- Time Travel: Replay narrative evolution over days/weeks
- Interactive RAG: Chat with your cluster data ("What are the top 3 complaints?")
- Export: PDF/PNG export of visualizations
- Docker: Containerized deployment
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create your 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
Distributed under the MIT License. See LICENSE for more information.
- Ollama for local LLM inference
- HuggingFace for pre-trained models
- D3.js for visualization primitives
- CardiffNLP for Twitter-specific models
Made with โค๏ธ by Suyesh Jadhav
