A Flask-based web application that analyzes text input and detects the underlying emotional tone. The application identifies five core emotions—anger, disgust, fear, joy, and sadness—and determines which emotion is most dominant in the given text.
- Real-time emotion analysis: Submit any text and receive instant emotion scores
- Multi-emotion detection: Analyzes text across five emotional dimensions
- Dominant emotion identification: Automatically highlights the strongest detected emotion
- Web interface: Clean, user-friendly UI for text input and results display
- REST API: Programmatic access via the
/emotionDetectorendpoint - Input validation: Graceful handling of invalid or empty text submissions
- Backend: Python, Flask
- Frontend: HTML, JavaScript
- NLP: Watson NLP / Embedded AI for emotion analysis
emotion-detector/
├── EmotionDetection/
│ ├── __init__.py
│ └── emotion_detection.py # Core emotion detection logic
├── static/
│ └── mywebscript.js # Frontend JavaScript
├── templates/
│ └── index.html # Web interface template
├── server.py # Flask application entry point
├── test_emotion_detection.py # Unit tests
├── LICENSE
└── README.md
-
Clone the repository
git clone https://github.com/ajitagupta/emotion-detector.git cd emotion-detector -
Create and activate a virtual environment (recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install flask requests
Start the Flask server:
python server.pyThe application will be available at http://localhost:5000.
- Open your browser and navigate to
http://localhost:5000 - Enter the text you want to analyze in the input field
- Click the analyze button to see the emotion breakdown
Send a GET request to the /emotionDetector endpoint:
curl "http://localhost:5000/emotionDetector?textToAnalyze=I%20am%20so%20happy%20today"Response format:
For the given statement, the system response is 'anger': 0.01, 'disgust': 0.02,
'fear': 0.01, 'joy': 0.95, 'sadness': 0.01. The dominant emotion is joy.
Execute the unit test suite:
python -m unittest test_emotion_detection| Emotion | Description |
|---|---|
| Anger | Frustration, irritation, or hostility |
| Disgust | Revulsion or strong disapproval |
| Fear | Anxiety, worry, or apprehension |
| Joy | Happiness, contentment, or excitement |
| Sadness | Sorrow, grief, or disappointment |
This project was developed as the final project for the IBM AI Engineering Professional Certificate on Coursera, specifically for the course on developing AI applications with Python and Flask.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Ajita Gupta
- GitHub: @ajitagupta
- Website: ajitagupta.com
- IBM Developer Skills Network for the course template and guidance
- Watson NLP for emotion detection capabilities