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.
- ๐ฌ 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-emotionsmodel. - ๐ก๏ธ 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.
The system is built as a set of decoupled microservices deployed on Google Cloud Run, connected to a Google Cloud SQL (MySQL) database.
chat-app-service(FastAPI): The core orchestrator. Handles WebSockets, user authentication, database management, and calls other AI services.ml-emotion-service(FastAPI + Transformers): A dedicated high-memory service that runs the Emotion Analysis model.ml-toxicity-service(FastAPI + Transformers): A dedicated high-memory service that runs the Toxicity Detection model.
-
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
- Hugging Face Transformers (
-
DevOps: Docker, Google Cloud Run, Google Artifact Registry
Follow these steps to run the project locally.
- Python 3.10+
- Docker (optional)
- MySQL Server (local or cloud)
git clone https://github.com/your-username/affective-chatroom.git
cd affective-chatroompython -m venv chat_env
# Windows
./chat_env/Scripts/activate
# Mac/Linux
source chat_env/bin/activatepip install -r chat-app/requirements.txt
pip install -r ml-emotion/requirements.txt
pip install -r ml-toxicity/requirements.txtCreate 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:8002cd ml-emotion
python main.py # Runs on port 8001cd ml-toxicity
python main.py # Runs on port 8002cd chat-app
uvicorn main:app --reload --port 8000Access the app at: http://127.0.0.1:8000
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-south1gcloud 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"- Mobile App using React Native
- Voice emotion recognition
- End-to-end encrypted private chatrooms
This project is open-source and available under the MIT License.