A powerful NLP-based web application that detects human emotions from text using state-of-the-art Transformer models.
Demo • Installation • Features • Usage • Contributing
| Feature | Description |
|---|---|
| 🎭 Multi-Emotion Detection | Detects 7 core emotions: anger, disgust, fear, joy, neutral, sadness, and surprise |
| 🚀 Real-Time Predictions | Instant emotion analysis with confidence scores |
| 🤖 Pre-trained Model | Powered by distilroberta-base fine-tuned on emotion datasets |
| 🌐 Web Interface | Clean, intuitive Flask-based UI for easy interaction |
| ⚡ Lightweight | Minimal dependencies, easy to deploy anywhere |
| Technology | Purpose |
|---|---|
| Python 3.9+ | Core programming language |
| Flask | Web framework for the application |
| HuggingFace Transformers | NLP model inference |
| PyTorch | Deep learning backend |
| HTML/CSS | Frontend interface |
emotion_detection/
├── 📄 app.py # Flask web application
├── 🧠 model.py # Emotion prediction logic
├── 📋 requirements.txt # Python dependencies
├── 📖 README.md # Project documentation
└── 📂 templates/
└── 🖼️ index.html # Web interface template
- Python 3.9 or higher
- pip (Python package manager)
- Git
-
Clone the repository
git clone https://github.com/your-username/emotion-detection.git cd emotion-detection -
Create a virtual environment (recommended)
python -m venv .venv # Windows .venv\Scripts\activate # macOS/Linux source .venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
python app.pyOpen your browser and navigate to:
from model import predict_emotion
# Get emotion prediction
text = "I am feeling very happy today!"
result = predict_emotion(text)
print(f"Emotion: {result['label']}")
print(f"Confidence: {result['score'] * 100:.2f}%")
|
|
| Input Text | Detected Emotion | Confidence |
|---|---|---|
| "I can't believe they did that to me!" | anger | 87% |
| "This is so scary..." | fear | 91% |
| "What a pleasant surprise!" | surprise | 89% |
| "I miss my old friends" | sadness | 85% |
This project uses the j-hartmann/emotion-english-distilroberta-base model from HuggingFace:
- Architecture: DistilRoBERTa (distilled version of RoBERTa)
- Training Data: Emotion-labeled English text datasets
- Emotions: anger, disgust, fear, joy, neutral, sadness, surprise
- Performance: Optimized for inference speed while maintaining accuracy
- 🏷️ Multi-label emotion classification
- ⚛️ React/Next.js frontend upgrade
- 📡 REST API endpoints for mobile apps
- 🔍 Model explainability (SHAP/LIME integration)
- ☁️ Cloud deployment (AWS/GCP/Heroku)
- 📊 Emotion trends visualization
- 🌍 Multi-language support
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
⭐ Star this repository if you found it helpful!
Made with ❤️ and Python