Skip to content

pradeep-mahat0/AI-Powered-Real-time-Affective-chatroom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽญ AI-Powered Real-Time Affective Chatroom

Project Status Python FastAPI Docker Google Cloud

A modern, intelligent chat platform that goes beyond text by understanding the emotional tone of conversations in real-time. This project uses a microservices architecture to detect emotions, moderate toxic content, and generate conversation summaries using advanced AI models.

Gemini_Generated_Image_tdl1g7tdl1g7tdl1 Screenshot 2025-12-02 231152 Screenshot 2025-12-02 231232 Screenshot 2025-12-02 231308 Screenshot 2025-12-02 231322

๐Ÿš€ Features

  • ๐Ÿ’ฌ Real-Time Messaging: Instant communication using WebSockets with zero latency.
  • ๐Ÿคฉ Real-Time Emotion Detection: Messages are automatically annotated with emojis representing 27 distinct emotions (e.g., Joy, Admiration, Fear) using the modernbert-base-go-emotions model.
  • ๐Ÿ›ก๏ธ AI-Powered Moderation: Automatically detects and blocks toxic content using roberta_toxicity_classifier, keeping the community safe.
  • ๐Ÿ“Š Smart Insights: Generates on-demand chat summaries and analyzes the overall "Room Mood" using Google Gemini 1.5 Flash.
  • โšก Asynchronous Architecture: Uses a "Broadcast-First, Update-Later" pattern to ensure the chat feels instant even while AI processing happens in the background.

๐Ÿ—๏ธ System Architecture

The system is built as a set of decoupled microservices deployed on Google Cloud Run, connected to a Google Cloud SQL (MySQL) database.

Microservices

  1. chat-app-service (FastAPI): The core orchestrator. Handles WebSockets, user authentication, database management, and calls other AI services.
  2. ml-emotion-service (FastAPI + Transformers): A dedicated high-memory service that runs the Emotion Analysis model.
  3. ml-toxicity-service (FastAPI + Transformers): A dedicated high-memory service that runs the Toxicity Detection model.

๐Ÿ› ๏ธ Tech Stack

  • Backend: Python 3.10, FastAPI, Uvicorn, Gunicorn

  • Frontend: HTML5, JavaScript (ES6), Tailwind CSS

  • Database: MySQL (Google Cloud SQL), SQLAlchemy (ORM)

  • AI & ML:

    • Hugging Face Transformers (modernbert, roberta)
    • LangChain + Google Gemini (LLM)
    • PyTorch
  • DevOps: Docker, Google Cloud Run, Google Artifact Registry


โš™๏ธ Local Development Setup

Follow these steps to run the project locally.

Prerequisites

  • Python 3.10+
  • Docker (optional)
  • MySQL Server (local or cloud)

1. Clone the Repository

git clone https://github.com/your-username/affective-chatroom.git
cd affective-chatroom

2. Set Up Virtual Environment

python -m venv chat_env
# Windows
./chat_env/Scripts/activate
# Mac/Linux
source chat_env/bin/activate

3. Install Dependencies

pip install -r chat-app/requirements.txt
pip install -r ml-emotion/requirements.txt
pip install -r ml-toxicity/requirements.txt

4. Configuration (.env)

Create a .env file in the chat-app/ directory:

DB_USER=root
DB_PASS=your_local_password
DB_HOST=127.0.0.1
DB_NAME=chatroom
SECRET_KEY=your_secret_key
GOOGLE_API_KEY=your_gemini_api_key

EMOTION_API_URL=http://127.0.0.1:8001
TOXICITY_API_URL=http://127.0.0.1:8002

5. Run the Services (3 Terminals)

Terminal 1 โ€” Emotion Service

cd ml-emotion
python main.py  # Runs on port 8001

Terminal 2 โ€” Toxicity Service

cd ml-toxicity
python main.py  # Runs on port 8002

Terminal 3 โ€” Main Chat App

cd chat-app
uvicorn main:app --reload --port 8000

Access the app at: http://127.0.0.1:8000


โ˜๏ธ Deployment (Google Cloud)

1. Deploy AI Services (High Memory)

gcloud run deploy ml-emotion-service --source ./ml-emotion --allow-unauthenticated --memory=4Gi --region=asia-south1
gcloud run deploy ml-toxicity-service --source ./ml-toxicity --allow-unauthenticated --memory=4Gi --region=asia-south1

2. Deploy Chat App (Standard Memory)

gcloud run deploy chat-app-service \
  --source ./chat-app \
  --allow-unauthenticated \
  --memory=1Gi \
  --region=asia-south1 \
  --set-env-vars="DB_USER=root,DB_PASS=YourDBPass,DB_NAME=chatroom,DB_HOST=YOUR_CLOUD_SQL_PUBLIC_IP,SECRET_KEY=secure-key,GOOGLE_API_KEY=your-key,TOXICITY_API_URL=https://url-to-toxicity-service,EMOTION_API_URL=https://url-to-emotion-service"

๐Ÿ”ฎ Future Scope

  • Mobile App using React Native
  • Voice emotion recognition
  • End-to-end encrypted private chatrooms

๐Ÿ“„ License

This project is open-source and available under the MIT License.

About

A real-time AI-powered chatroom that detects emotions, blocks toxic content, and generates conversation insights using microservices and modern Transformer models

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors