abdelrahman-hsn/sentiment-service

Python

0

1 commits

updated Dec 26, 2025

See the code

README

Sentiment Analysis Service - README

A high-throughput, real-time sentiment analysis system for Arabic chat messages.

Quick Start

1. Start RabbitMQ

docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management

2. Install Python Dependencies

cd sentiment-service
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

3. Download Sample Data & Run Worker

# Create sample dataset
python training/download_datasets.py

# Run worker (in mock mode without trained model)
python -m app.worker

4. Rails Setup

cd ../romanh
bundle install
rails db:migrate

# Add to .env
SENTIMENT_SERVICE_ENABLED=true
RABBITMQ_URL=amqp://guest:guest@localhost:5672

Architecture

Rails App (romanh)          RabbitMQ            Sentiment Service
┌─────────────────┐        ┌─────────┐         ┌─────────────────┐
│ Message Created │───────▶│analyze  │────────▶│ Python Worker   │
│                 │        │         │         │ (ONNX Model)    │
│ Update Message  │◀───────│result   │◀────────│                 │
│ Action Cable    │        └─────────┘         └─────────────────┘
└─────────────────┘

Training Your Own Model

cd sentiment-service
source venv/bin/activate

# 1. Download datasets
python training/download_datasets.py

# 2. Preprocess
python training/preprocessing.py --split

# 3. Train (requires GPU)
python training/train.py --config training/config.yaml

# 4. Export to ONNX
python training/export_onnx.py --checkpoint models/checkpoints/bert-base-arabertv02_best --output models/sentiment_ensemble.onnx

API Endpoints

# Health check
curl http://localhost:8000/health

# Predict sentiment
curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "شكراً جداً، خدمة ممتازة!"}'

Docker Deployment

cd sentiment-service
docker-compose up -d

Features

  • Arabic Dialects: Egyptian, Gulf, Levantine, MSA, Maghrebi
  • Sentiment Labels: Positive, Neutral, Negative
  • Emotion Detection: Angry, Frustrated, Happy, Satisfied, etc.
  • Real-time Alerts: Action Cable broadcasts for angry customers
  • High Throughput: 1M+ messages/minute with horizontal scaling

abdelrahman-hsn/sentiment-service

Python

0

1 commits

updated Dec 26, 2025

See the code

README

Sentiment Analysis Service - README

A high-throughput, real-time sentiment analysis system for Arabic chat messages.

Quick Start

1. Start RabbitMQ

docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management

2. Install Python Dependencies

cd sentiment-service
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

3. Download Sample Data & Run Worker

# Create sample dataset
python training/download_datasets.py

# Run worker (in mock mode without trained model)
python -m app.worker

4. Rails Setup

cd ../romanh
bundle install
rails db:migrate

# Add to .env
SENTIMENT_SERVICE_ENABLED=true
RABBITMQ_URL=amqp://guest:guest@localhost:5672

Architecture

Rails App (romanh)          RabbitMQ            Sentiment Service
┌─────────────────┐        ┌─────────┐         ┌─────────────────┐
│ Message Created │───────▶│analyze  │────────▶│ Python Worker   │
│                 │        │         │         │ (ONNX Model)    │
│ Update Message  │◀───────│result   │◀────────│                 │
│ Action Cable    │        └─────────┘         └─────────────────┘
└─────────────────┘

Training Your Own Model

cd sentiment-service
source venv/bin/activate

# 1. Download datasets
python training/download_datasets.py

# 2. Preprocess
python training/preprocessing.py --split

# 3. Train (requires GPU)
python training/train.py --config training/config.yaml

# 4. Export to ONNX
python training/export_onnx.py --checkpoint models/checkpoints/bert-base-arabertv02_best --output models/sentiment_ensemble.onnx

API Endpoints

# Health check
curl http://localhost:8000/health

# Predict sentiment
curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "شكراً جداً، خدمة ممتازة!"}'

Docker Deployment

cd sentiment-service
docker-compose up -d

Features

  • Arabic Dialects: Egyptian, Gulf, Levantine, MSA, Maghrebi
  • Sentiment Labels: Positive, Neutral, Negative
  • Emotion Detection: Angry, Frustrated, Happy, Satisfied, etc.
  • Real-time Alerts: Action Cable broadcasts for angry customers
  • High Throughput: 1M+ messages/minute with horizontal scaling