Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

🧠 Real-Time Tweet Sentiment Analysis

A complete real-time sentiment analysis pipeline that streams live tweets, processes them through Apache Kafka and Apache Spark MLlib, stores results in MongoDB, and visualizes outcomes via a Flask frontend.


📊 System Architecture

Architecture Diagram

Workflow Overview

  1. Twitter Tweets → Streamed via API to Kafka Producer.

  2. Kafka Broker → Buffers and distributes tweets to Spark consumers.

  3. Spark MLlib →

    • Model training (offline).
    • Real-time prediction (online).
  4. MongoDB → Stores classified tweets (positive, negative, neutral).

  5. Flask App → Fetches sentiment data from MongoDB for visualization.


⚙️ Prerequisites

  • Docker & Docker Compose
  • Python 3.x
  • Apache Kafka
  • Apache Spark
  • MongoDB
  • Flask

🧩 Directory Structure

BDS_Assignment/
│
├── Kafka-Streaming.py        # Spark Streaming consumer
├── Spark/                    # Jupyter workspace (for model training)
├── Application-FLASK/
│   └── main.py               # Flask backend
├── docker-compose.yml
├── Dockerfile                # Spark-Jupyter image
└── README.md

🚀 Setup & Execution

Step 1: Start all services

docker-compose up -d

Step 2: Build Spark-Jupyter image

docker build -t spark-jupyter:latest .

Step 3: Run Spark-Jupyter container

docker run -e MONGO_USERNAME="" -e MONGO_PASSWORD="" \
  -p 8888:8888 \
  -v B:\BDS_Assignment\Spark:/home/xyz/work \
  --network bds_assignment_kafka-net \
  spark-jupyter:latest

Open the Jupyter notebook from the browser using the token printed in the container logs.


Step 4: Enter container shell

docker exec -it <jupyter-container-id> /bin/bash
cd home/xyz/work

Step 5: Run Spark Streaming

spark-submit Kafka-Streaming.py

🌐 Flask Frontend

Step 6: Start the Flask app

cd Application-FLASK
python main.py

The app exposes endpoints to visualize tweet sentiments and trends.


🧠 Model Training

  1. Use Jupyter Notebook inside the Spark/ directory to train sentiment analysis models with Spark MLlib.
  2. Save the trained model and load it in the streaming job (Kafka-Streaming.py).

🗄️ Data Storage

All classified tweets are stored in MongoDB, including:

  • Tweet text
  • Timestamp
  • Sentiment label
  • Confidence score

🖥️ Visualization

The Flask app fetches data from MongoDB and renders:

  • Real-time sentiment count charts
  • Historical trend lines
  • Word clouds or hashtags (optional)

🧰 Tech Stack

Component Technology
Data Streaming Apache Kafka
Real-time Processing Apache Spark (PySpark)
ML Model Spark MLlib
Database MongoDB
API Backend Flask
Frontend HTML / JS / Charts.js
Containerization Docker

📦 Network

All containers (Kafka, Spark, MongoDB, Flask) communicate on the same Docker network:

bds_assignment_kafka-net

🧑‍💻 Contributors

  • Shrey Vyas – Project Developer

🏁 Future Improvements

  • Integration with Twitter API v2 for live streams
  • Dashboard for real-time analytics
  • Model fine-tuning using BERT or LSTM

🎯 Goal: Deliver live tweet sentiment insights using scalable big data technologies.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages