Spaces:
Sleeping
Sleeping
Update README.md, added workflow, and changed order of sections
Browse files
README.md
CHANGED
|
@@ -1,105 +1,100 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Real-Time Sentiment Analysis Dashboard
|
| 3 |
-
emoji: π
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: green
|
| 6 |
-
sdk: docker
|
| 7 |
-
app_port: 7860
|
| 8 |
-
pinned: false
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# π Sentiment Analysis Dashboard
|
| 12 |
-
|
| 13 |
-
A real-time sentiment analysis dashboard that processes tweets and displays sentiment trends.
|
| 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 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
-
|
| 95 |
-
-
|
| 96 |
-
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-

|
| 103 |
-

|
| 104 |
-
|
| 105 |
-
*Demo hosted on Hugging Face Spaces with mock data for demonstration purposes.*
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Real-Time Sentiment Analysis Dashboard
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# π Sentiment Analysis Dashboard
|
| 12 |
+
|
| 13 |
+
A real-time sentiment analysis dashboard that processes tweets and displays sentiment trends using Apache Kafka, Spark, and Docker.
|
| 14 |
+
|
| 15 |
+
**Live Demo Dashboard**: [https://huggingface.co/spaces/xtinkarpiu/sentiment-analysis](https://huggingface.co/spaces/xtinkarpiu/sentiment-analysis). *Demo runs in mock mode with simulated tweets*
|
| 16 |
+
|
| 17 |
+
Author: Kristine Karp (karpkristine@gmail.com)
|
| 18 |
+
|
| 19 |
+
## πΈ Preview
|
| 20 |
+

|
| 21 |
+

|
| 22 |
+
|
| 23 |
+
## π Features
|
| 24 |
+
|
| 25 |
+
- Real-time tweet processing - Live streaming with Apache Kafka
|
| 26 |
+
- Intelligent sentiment analysis - Keyword-based classification with Spark
|
| 27 |
+
- Live dashboard updates - WebSocket-powered real-time interface
|
| 28 |
+
- Comprehensive visualization - Sentiment trends and recent tweet streams
|
| 29 |
+
- Flexible data sources - Support for both live Twitter API and mock data
|
| 30 |
+
- Containerized deployment - Full Docker orchestration for easy setup
|
| 31 |
+
|
| 32 |
+
## βοΈ Workflow Overview
|
| 33 |
+
This project implements a real-time sentiment analysis ETL pipeline using **Python scripts**, all orchestrated with **Docker**:
|
| 34 |
+
|
| 35 |
+
1. **Extract** - `producer.py` connects to Twitter API for live streaming, or mock_tweet_producer.py generates realistic demo data for testing or hugging face demonstration purposes.
|
| 36 |
+
2. **Transform** - Apache Kafka ingests tweets under 'sentiment-topic', while `consumer.py` applies sentiment analysis using Spark streaming.
|
| 37 |
+
3. **Load** - Processed results are published to 'sentiment-results' topic and displayed in real-time, also in `consumer.py`.
|
| 38 |
+
4. **Visualization** - `dashboard.py` provides a web interface with live sentiment metrics and trend charts.
|
| 39 |
+
5. **Orchestrate** - `docker-compose.yml` and `Docker` manages all services for consistent deployment.
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## π§ͺ How to Reproduce Locally
|
| 44 |
+
|
| 45 |
+
**Option 1: Mock Mode (No API Required)**
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
git clone https://huggingface.co/spaces/xtinkarpiu/sentiment-analysis
|
| 49 |
+
cd sentiment-analysis
|
| 50 |
+
docker-compose up --build
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
This launches:
|
| 54 |
+
|
| 55 |
+
- Kafka: Message broker for tweet streaming
|
| 56 |
+
- Spark: Real-time sentiment analysis processing
|
| 57 |
+
- Producer: Tweet ingestion (default: mock tweets)
|
| 58 |
+
- Dashboard: Web interface at http://localhost:5000
|
| 59 |
+
|
| 60 |
+
**Option 2: Live Twitter Integration**
|
| 61 |
+
|
| 62 |
+
1. Create a Twitter/X Developer App at [developer.twitter.com](https://developer.twitter.com). Ensure your app has read and write permissions enabled, and your API access level is at least Basic to access streaming endpoints.
|
| 63 |
+
2. Add your **Bearer Token** to a `.env` file:
|
| 64 |
+
```env
|
| 65 |
+
BEARER_TOKEN=your_token_here
|
| 66 |
+
```
|
| 67 |
+
3. Set mock mode to false in `app.py`:
|
| 68 |
+
```python
|
| 69 |
+
os.environ["USE_MOCK"] = "false"
|
| 70 |
+
```
|
| 71 |
+
4. In `docker-compose.yml`, under sentiment-producer, replace the command to run producer.py instead of mock_tweet_producer.py:
|
| 72 |
+
```python
|
| 73 |
+
command: ["python", "producer.py"]
|
| 74 |
+
```
|
| 75 |
+
5. Restart the Docker Compose stack to begin processing live tweets.
|
| 76 |
+
```bash
|
| 77 |
+
docker-compose up --build
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
## π οΈ Project Structure
|
| 81 |
+
|
| 82 |
+
| File/Folder | Purpose |
|
| 83 |
+
|------------------------|---------------------------------------------------|
|
| 84 |
+
| `dashboard.py` | Flask app + Kafka consumer for real-time dashboard, flexible for real Kafka data or Hugging Face demo data |
|
| 85 |
+
| `templates/dashboard.html` | HTML UI template with real-time charts and tweet display |
|
| 86 |
+
| `mock_tweet_producer.py` | Generates realistic mock tweets for demo/testing |
|
| 87 |
+
| `producer.py` | Connects to Twitter API to stream live tweets |
|
| 88 |
+
| `consumer.py` | Runs Spark-based sentiment analysis on Kafka stream |
|
| 89 |
+
| `docker-compose.yml` | Docker setup orchestrating Kafka, Spark, producer, dashboard |
|
| 90 |
+
| `requirements.txt` | Python dependencies |
|
| 91 |
+
| `.env` (optional) | Contains Twitter API credentials |
|
| 92 |
+
|
| 93 |
+
## π§ Tech Stack
|
| 94 |
+
- Backend: Python, Flask, Flask-SocketIO
|
| 95 |
+
- Message Streaming: Apache Kafka
|
| 96 |
+
- Stream Processing: Apache Spark
|
| 97 |
+
- Frontend: HTML5, CSS3, JavaScript, Chart.js
|
| 98 |
+
- Real-time Communication: WebSocket
|
| 99 |
+
- Containerization: Docker, Docker Compose
|
| 100 |
+
- API Integration: Twitter API v2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|