A complete AI-powered emotional support chatbot built with Flask (backend) and Next.js (frontend).
┌─────────────┐ POST /chat ┌─────────────────────────────────────┐
│ Next.js │ ──────────────────► │ Flask Backend │
│ Frontend │ ◄────────────────── │ │
│ (React) │ JSON Response │ RoBERTa → Crisis → Gemini → DialoGPT│
└─────────────┘ └─────────────────────────────────────┘
| Layer | Technology |
|---|---|
| Backend | Flask (Python) |
| Frontend | Next.js 14 (React) |
| Emotion Detection | SamLowe/roberta-base-go_emotions |
| Empathy Refinement | AliiaR/DialoGPT-medium-empathetic-dialogues |
| Response Generation | Gemini API |
AI_Counselling_System_Fullstack/
├── backend/
│ ├── app.py # Flask application
│ ├── requirements.txt # Python dependencies
│ ├── .env.example # Environment template
│ ├── models/
│ │ ├── emotion.py # RoBERTa emotion detector
│ │ ├── crisis.py # Crisis detection logic
│ │ └── empathy.py # DialoGPT empathy refiner
│ └── services/
│ └── gemini.py # Gemini API integration
├── frontend/
│ ├── package.json
│ ├── next.config.js
│ ├── .env.local.example
│ ├── app/
│ │ ├── layout.js # Root layout
│ │ └── page.js # Main page
│ └── components/
│ └── ChatBox.js # Chat UI component
└── README.md
cd backend
copy .env.example .env
# Edit .env and add your GEMINI_API_KEY
pip install -r requirements.txt
python app.pyThe backend will start on http://localhost:5000.
cd frontend
copy .env.local.example .env.local
npm install
npm run devThe frontend will start on http://localhost:3000.
- Go to https://aistudio.google.com/app/apikey
- Create an API key
- Add it to
backend/.env
| Endpoint | Method | Description |
|---|---|---|
/chat |
POST | Send message and get AI response |
/mood |
GET | Get mood history |
/reset |
POST | Reset conversation |
/health |
GET | Health check |
POST /chat
{
"message": "I'm feeling really stressed about work"
}{
"response": "AI empathetic response...",
"emotion": "stress",
"secondary_emotion": "anxiety",
"intensity": "high",
"crisis": false,
"crisis_level": "none",
"mood_history": [...]
}- Emotion Detection - Real-time emotion analysis using RoBERTa
- Crisis Detection - Automatic detection of crisis situations
- Empathetic Responses - Gemini-powered responses refined by DialoGPT
- Music Suggestions - Calming music recommendations based on emotion
- Breathing Exercises - Guided breathing techniques for crisis situations
- Mental Exercises - Grounding exercises for emotional regulation
- Mood Tracking - Tracks emotional history across conversations
- Crisis Support - Hotline suggestions and urgent care guidance
This system provides emotional support but is NOT a replacement for professional mental health care. If you're in crisis, please contact emergency services or a crisis hotline immediately.