|
| 1 | +# EmoBot v2 — Emotion-Aware Multilingual Chatbot |
| 2 | + |
| 3 | +An emotionally intelligent chatbot that detects the user's emotion from their message using **XLM-RoBERTa** and generates empathetic, tone-aligned responses via **Google Gemini**. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **Real-time emotion detection** — XLM-RoBERTa fine-tuned on GoEmotions (28 emotion labels) |
| 10 | +- **Empathetic AI responses** — Gemini adapts tone based on detected emotion (sadness → warm, anger → calm, joy → upbeat, ...) |
| 11 | +- **Multilingual** — Detects emotion and responds in the user's language |
| 12 | +- **Voice input & output** — Speech-to-text (Web Speech API + Whisper fallback) and text-to-speech (Edge TTS + browser fallback) |
| 13 | +- **Automatic model fallback** — If Gemini 2.5 Flash quota is exhausted, falls back to Gemma 3 4B seamlessly |
| 14 | +- **Emotion badges** — Detected emotion displayed on both user and bot messages |
| 15 | +- **Chat actions** — Copy, like/dislike feedback, download conversation as JSON, new chat |
| 16 | +- **Dark mode** — Toggle between light and dark themes |
| 17 | +- **Glassmorphism UI** — Frosted glass cards, animated floating orbs, gradient accents |
| 18 | +- **Security hardened** — CSP headers, rate limiting, input sanitization |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## How It Works |
| 23 | + |
| 24 | +``` |
| 25 | +User Message |
| 26 | + │ |
| 27 | + ▼ |
| 28 | +┌──────────────────────┐ |
| 29 | +│ XLM-RoBERTa │──→ Detected emotion (e.g. "joy", "sadness", "anger") |
| 30 | +│ Emotion Classifier │ + confidence scores (top 3) |
| 31 | +└──────────────────────┘ |
| 32 | + │ |
| 33 | + ▼ |
| 34 | +┌──────────────────────┐ |
| 35 | +│ Google Gemini │──→ Emotionally aligned response |
| 36 | +│ (2.5 Flash / Gemma) │ in the user's language |
| 37 | +└──────────────────────┘ |
| 38 | + │ |
| 39 | + ▼ |
| 40 | +Chat UI displays response + emotion badge |
| 41 | +``` |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## Tech Stack |
| 46 | + |
| 47 | +| Layer | Technology | |
| 48 | +| ------------- | --------------------------------------- | |
| 49 | +| Backend | Python, Flask | |
| 50 | +| Emotion Model | XLM-RoBERTa (GoEmotions, 28 labels) | |
| 51 | +| Response Gen | Gemini 2.5 Flash (fallback: Gemma 3 4B) | |
| 52 | +| TTS | Edge TTS (14 language voices) | |
| 53 | +| STT | Web Speech API + OpenAI Whisper | |
| 54 | +| Frontend | HTML, CSS, JavaScript | |
| 55 | +| Database | MongoDB (optional, in-memory fallback) | |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Project Structure |
| 60 | + |
| 61 | +``` |
| 62 | +EmoBot/ |
| 63 | +├── app.py # Flask backend (API, emotion detection, Gemini, TTS/STT) |
| 64 | +├── requirements.txt # Python dependencies |
| 65 | +├── .env.example # Environment variable template |
| 66 | +├── .gitignore |
| 67 | +├── README.md |
| 68 | +├── xlm-roberta.ipynb # Model training notebook |
| 69 | +│ |
| 70 | +├── static/ |
| 71 | +│ ├── css/ |
| 72 | +│ │ └── main.css # Full stylesheet (glassmorphism, animations, dark mode) |
| 73 | +│ ├── js/ |
| 74 | +│ │ ├── chat.js # Chat logic (send, receive, TTS, STT, feedback, download) |
| 75 | +│ │ └── home.js # Landing page (emotion pills, scroll reveal, dark mode) |
| 76 | +│ └── models/ |
| 77 | +│ └── xlm-roberta_emotion_model/ |
| 78 | +│ ├── model.safetensors # Fine-tuned weights (~1.1 GB, Git LFS) |
| 79 | +│ ├── config.json |
| 80 | +│ ├── tokenizer_config.json |
| 81 | +│ ├── sentencepiece.bpe.model |
| 82 | +│ └── special_tokens_map.json |
| 83 | +│ |
| 84 | +└── templates/ |
| 85 | + ├── index.html # Landing page |
| 86 | + ├── chat.html # Chat interface |
| 87 | + ├── 404.html # Not found page |
| 88 | + └── 500.html # Server error page |
| 89 | +``` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Setup |
| 94 | + |
| 95 | +### 1. Clone & pull model weights |
| 96 | + |
| 97 | +```bash |
| 98 | +git clone https://github.com/anVSS1/emobot.git |
| 99 | +cd emobot |
| 100 | +git lfs install |
| 101 | +git lfs pull |
| 102 | +``` |
| 103 | + |
| 104 | +### 2. Create virtual environment |
| 105 | + |
| 106 | +```bash |
| 107 | +python -m venv .venv |
| 108 | +# Windows |
| 109 | +.venv\Scripts\activate |
| 110 | +# macOS / Linux |
| 111 | +source .venv/bin/activate |
| 112 | +``` |
| 113 | + |
| 114 | +### 3. Install dependencies |
| 115 | + |
| 116 | +```bash |
| 117 | +pip install -r requirements.txt |
| 118 | +``` |
| 119 | + |
| 120 | +### 4. Configure environment |
| 121 | + |
| 122 | +```bash |
| 123 | +cp .env.example .env |
| 124 | +``` |
| 125 | + |
| 126 | +Edit `.env` and add your [Google AI Studio API key](https://aistudio.google.com/apikey): |
| 127 | + |
| 128 | +``` |
| 129 | +GEMINI_API_KEY=your_key_here |
| 130 | +``` |
| 131 | + |
| 132 | +### 5. Run |
| 133 | + |
| 134 | +```bash |
| 135 | +python -u app.py |
| 136 | +``` |
| 137 | + |
| 138 | +Open **http://localhost:5000** and start chatting. |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +## Environment Variables |
| 143 | + |
| 144 | +| Variable | Default | Description | |
| 145 | +| ---------------- | ---------------------------- | ----------------------------------- | |
| 146 | +| `GEMINI_API_KEY` | _(required)_ | Google AI Studio API key | |
| 147 | +| `GEMINI_MODEL` | `gemini-2.5-flash` | Primary generation model | |
| 148 | +| `FALLBACK_MODEL` | `gemma-3-4b-it` | Fallback model when quota exhausted | |
| 149 | +| `SECRET_KEY` | _(auto-generated)_ | Flask session secret | |
| 150 | +| `MONGODB_URI` | `mongodb://localhost:27017/` | MongoDB connection string | |
| 151 | +| `HOST` | `127.0.0.1` | Server bind address | |
| 152 | +| `PORT` | `5000` | Server port | |
| 153 | +| `FLASK_DEBUG` | `false` | Enable Flask debug mode | |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## Supported Emotions (28) |
| 158 | + |
| 159 | +admiration · amusement · anger · annoyance · approval · caring · confusion · curiosity · desire · disappointment · disapproval · disgust · embarrassment · excitement · fear · gratitude · grief · joy · love · nervousness · optimism · pride · realization · relief · remorse · sadness · surprise · neutral |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +## Team |
| 164 | + |
| 165 | +| Name | Links | |
| 166 | +| ------------------- | --------------------------------------------------------------------------------------------------------------------- | |
| 167 | +| **Anass Ouzaouit** | [GitHub](https://github.com/anVSS1) · [LinkedIn](https://linkedin.com/in/anass-ouzaouit) · [X](https://x.com/anvss__) | |
| 168 | +| **Mohamed Kannoun** | [LinkedIn](https://linkedin.com/in/kannoun) · [X](https://x.com/M_KANNOUN) | |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +## License |
| 173 | + |
| 174 | +MIT |
0 commit comments