EmoSense is an AI-powered emotion analysis chatbot that uses a fine-tuned BERT model to detect and analyze emotions in text. Built with Streamlit, it provides an interactive chat interface that identifies up to 28 different emotions from the GoEmotions dataset.
- Real-time Emotion Detection: Analyze text and detect 28 different emotions including joy, anger, sadness, excitement, fear, love, and more
- Interactive Chat Interface: Conversational UI with chat bubbles and message history
- Smart Emotional Summary 🧠 NEW:
- AI-powered text summarization using Hugging Face BART model
- Combines emotion analysis with intelligent text summary
- Emotion-based reasoning and keyword detection
- Context-aware suggested actions for each emotion type
- Export results as Markdown or JSON
- Beautiful visual presentation with emotion breakdowns
- Bulk Comment Analysis: Upload CSV files or paste multiple comments for batch processing
- Analytics Dashboard:
- Top 4 emotions with metric cards
- Bar charts showing emotion distribution
- Pie charts for percentage breakdown
- Detailed statistics table
- Download results as CSV
- AI-Powered Insights:
- Automated summary generation using OpenAI GPT
- Sentiment overview and key emotion analysis
- Identification of positive signals and concerns
- Actionable recommendations based on emotional landscape
- Priority actions for critical issues
- Download AI insights as markdown report
- Visual Analytics:
- Colorful emotion chips with probability scores
- Emoji representations for each emotion
- Customizable Threshold: Adjust confidence threshold to filter emotion predictions
- Chat History: Persistent conversation history during your session
- Dark Theme: Modern dark UI with gradient accents
The model can detect 28 emotions from the GoEmotions dataset:
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
- Python 3.8 or higher
- A trained BERT emotion model saved in
./emotion_bert_model/
-
Clone the repository
git clone <repository-url> cd emosense_backend
-
Install dependencies
pip install -r requirements.txt
-
Ensure model files are in place
Make sure you have your trained BERT model in the
./emotion_bert_model/directory with:config.jsonpytorch_model.bin(ormodel.safetensors)tokenizer_config.jsonvocab.txt
-
Run the application
streamlit run app.py
-
Open in browser
The app will automatically open in your default browser at
http://localhost:8501
-
Push your code to GitHub
git init git add . git commit -m "Initial commit" git remote add origin <your-github-repo-url> git push -u origin main
-
Visit Streamlit Cloud
- Go to share.streamlit.io
- Sign in with your GitHub account
-
Deploy the app
- Click "New app"
- Select your repository
- Choose the branch (usually
main) - Set main file path:
app.py - Click "Deploy"
- BERT models can be large (>400MB)
- Streamlit Cloud has storage and memory limits
- Consider using a smaller model or model compression techniques
- Alternatively, host the model externally (e.g., HuggingFace Hub) and load it via API
Loading from HuggingFace Hub (Alternative):
# In utils/predict.py, replace MODEL_PATH with:
MODEL_PATH = "your-username/emotion-bert-model" # Your HuggingFace modelemosense_backend/
├── app.py # Main Streamlit application
├── requirements.txt # Python dependencies
├── .streamlit/
│ └── config.toml # Streamlit configuration (dark theme)
├── services/
│ └── summary_service.py # Smart Emotional Summary service
├── components/
│ └── emotional_summary_card.py # UI component for summary display
├── utils/
│ ├── predict.py # Model loading and prediction logic
│ ├── labels.py # Emotion labels and emoji mappings
│ ├── ai_summary.py # AI-powered insights generation
│ └── mock_predict.py # Mock predictions for testing
├── tests/
│ └── test_summary.py # Unit tests for summary service
└── emotion_bert_model/ # Trained BERT model (not included in repo)
├── config.json
├── pytorch_model.bin
└── tokenizer files
- Frontend: Streamlit
- ML Framework: PyTorch, Transformers (HuggingFace)
- Emotion Model: BERT fine-tuned on GoEmotions dataset (hosted on HuggingFace Hub)
- Summarization Model: BART (facebook/bart-large-cnn) via HuggingFace Inference API
- AI Insights: OpenAI GPT-4o-mini
- Visualization: Matplotlib
- Data Processing: Pandas
- Language: Python 3.8+
- User enters text in the chat interface or uploads bulk comments
- Text is tokenized using BERT tokenizer
- Model processes the input and outputs logits for 28 emotion classes
- Sigmoid activation converts logits to probabilities
- Emotions above the threshold are displayed with emojis and confidence scores
- Results visualized as colorful chips, bar charts, and pie charts
- User enters text (single or bulk input)
- Text is cleaned and validated (10-1000 words)
- Hugging Face BART model generates concise summary via Inference API
- Emotion classifier analyzes the text simultaneously
- Service combines results with intelligent reasoning:
- Matches emotion keywords in summary
- Generates context-aware explanations
- Provides emotion-specific suggested actions
- Beautiful UI card displays:
- AI-generated summary
- Dominant emotion with confidence
- Full emotion probability breakdown
- Reasoning and detected keywords
- Suggested actions (de-escalation, grounding, etc.)
- Export results as Markdown or JSON
- After bulk analysis, emotion data is aggregated
- AI analyzes emotion distribution and sample comments
- OpenAI GPT generates professional insights including:
- Overall sentiment assessment
- Key emotion patterns
- Positive signals and concerns
- Actionable recommendations
- Priority actions for critical issues
- Report can be downloaded as markdown
For Smart Emotional Summary, configure your Hugging Face API key:
Option 1: Streamlit Cloud Secrets (Recommended for deployment)
- Go to your app settings on Streamlit Cloud
- Navigate to "Secrets" section
- Add the following:
HUGGINGFACE_API_KEY = "hf_your-api-key-here"
Option 2: Local Development
- Set environment variable:
$env:HUGGINGFACE_API_KEY="hf-your-key"(Windows PowerShell) - Or:
export HUGGINGFACE_API_KEY=hf-your-key(Linux/Mac)
For AI-powered insights, configure your OpenAI API key:
Option 1: Streamlit Cloud Secrets (Recommended for deployment)
- Go to your app settings on Streamlit Cloud
- Navigate to "Secrets" section
- Add the following:
OPENAI_API_KEY = "sk-your-api-key-here"
Option 2: Local Development
- Set environment variable:
set OPENAI_API_KEY=sk-your-key(Windows) - Or enter the key directly in the app interface (session only)
Option 3: Manual Entry
- Use the expandable section in the app to enter your key temporarily
Use the sidebar slider to change the minimum probability required for an emotion to be displayed (default: 0.3)
Edit .streamlit/config.toml to customize colors and appearance
Update the MODEL_ID in utils/predict.py to use a different HuggingFace model
This project is open source and available under the MIT License.
Contributions are welcome! Feel free to open issues or submit pull requests.
- Multi-language support
- Voice input for emotion analysis
- Export chat history
- Emotion trends over conversation
- API endpoint for integration
Built with ❤️ using Streamlit and BERT