xtinkarpiu commited on
Commit
b97c280
Β·
verified Β·
1 Parent(s): 7332011

Update README.md, added workflow, and changed order of sections

Browse files
Files changed (1) hide show
  1. README.md +100 -105
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
- - 🟒 **Live Demo Mode**: Shows mock data for demonstration
16
- - πŸ”„ **Real-time Updates**: Uses WebSocket for live data streaming
17
- - πŸ“Š **Interactive Charts**: Pie charts and trend analysis
18
- - πŸ“± **Recent Tweets**: Live feed of processed tweets
19
-
20
- This version runs in mock/demo mode on Hugging Face Spaces.
21
- To run, go to 'App' tab, and click 'Restart Space'
22
-
23
- ## πŸ”§ Technologies Used
24
- - Backend: Python, Flask, Flask-SocketIO
25
- - Message Streaming: Apache Kafka
26
- - Stream Processing: Apache Spark
27
- - Frontend: HTML5, CSS3, JavaScript, Chart.js
28
- - Real-time Communication: WebSocket
29
- - Containerization: Docker, Docker Compose
30
- - API Integration: Twitter API v2
31
-
32
- Author: Kristine Karp (karpkristine@gmail.com)
33
-
34
- ---
35
-
36
- ## πŸš€ Demo Mode (Hugging Face)
37
-
38
- - This Space runs in **mock mode**, generating fake tweets using `mock_tweet_producer.py`.
39
- - This allows users to explore the dashboard **without requiring Twitter API credentials or external Kafka setup**.
40
-
41
- - If you have a Twitter API token, you can use `producer.py` and set `os.environ["USE_MOCK"]` to `"false"` in `app.py`.
42
-
43
-
44
- ---
45
-
46
- ## 🧠 Features
47
-
48
- - Real-time tweet ingestion (simulated or live)
49
- - Sentiment analysis using keyword-based classification
50
- - Live sentiment counts: Positive, Neutral, Negative
51
- - Recent tweet stream with color-coded sentiment tags
52
- - Hourly sentiment trend visualization
53
- - WebSocket-powered live dashboard updates
54
- - Responsive design with modern UI
55
-
56
- ---
57
-
58
- ## πŸ› οΈ File Overview
59
-
60
- | File/Folder | Purpose |
61
- |------------------------|---------------------------------------------------|
62
- | `dashboard.py` | Main Flask app + Kafka consumer, flexible for real Kafka data or Hugging Face demo |
63
- | `templates/dashboard.html` | HTML UI template with real-time charts and tweet display |
64
- | `mock_tweet_producer.py` | Generates realistic mock tweets for demo/testing |
65
- | `producer.py` | Twitter API producer for live tweet streaming |
66
- | `consumer.py` | Spark-based sentiment analysis processor |
67
- | `docker-compose.yml` | Full microservices setup (Kafka + Spark + Dashboard) |
68
- | `requirements.txt` | Python dependencies |
69
- | `.env` (optional) | Twitter API credentials for live data |
70
-
71
- ---
72
-
73
- ## πŸ“‘ Using Real Twitter Streaming
74
-
75
- If you want to stream real tweets and analyze their sentiment:
76
-
77
- 1. Create a Twitter/X Developer App at [developer.twitter.com](https://developer.twitter.com)
78
- 2. Add your **Bearer Token** to a `.env` file:
79
- ```env
80
- BEARER_TOKEN=your_token_here
81
- 3. Set mock mode to false in app.py:
82
- os.environ["USE_MOCK"] = "false"
83
- 4. Run producer.py instead. Run with real data: The system will connect to Twitter API and process live tweets
84
-
85
- ## πŸ§ͺ Local Development
86
-
87
- 1. git clone https://huggingface.co/spaces/xtinkarpiu/sentiment-analysis
88
- 2. cd sentiment-analysis
89
- 3. docker-compose up --build
90
-
91
- This will start:
92
-
93
- - πŸ”΄ Kafka: Message broker for tweet streaming
94
- - ⚑ Spark: Real-time sentiment analysis processing
95
- - 🐍 Producer: Tweet ingestion (mock or real)
96
- - πŸ“Š Dashboard: Web interface at http://localhost:5000
97
-
98
- ## πŸ“· Dashboard Preview
99
-
100
- Here's a preview of the sentiment dashboard in action:
101
-
102
- ![Dashboard Overview](assets/dashboard_screenshot1.jpg)
103
- ![Real-Time Tweets and Charts](assets/dashboard_screenshot2.jpg)
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
+ ![Dashboard Overview](assets/dashboard_screenshot1.jpg)
21
+ ![Real-Time Tweets and Charts](assets/dashboard_screenshot2.jpg)
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