This project is an Emotion Detection Web Application built using Python and Flask. It leverages the Watson NLP library (specifically the EmotionPredict service) to analyze text and predict the presence of five primary emotions: anger, disgust, fear, joy, and sadness. The application then determines the dominant emotion and presents the results through an interactive web interface.
This project was developed as part of the IBM Skills Network and IBM AI Developer Professional Certificate.
- Text Analysis: Enter any statement to analyze the underlying emotions.
- Emotion Scoring: Returns confidence scores for anger, disgust, fear, joy, and sadness.
- Dominant Emotion Identification: Automatically calculates and highlights the most prominent emotion.
- Error Handling: Gracefully handles blank entries and invalid inputs with friendly error messages.
- Web Interface: Clean, simple frontend for interacting with the AI model.
- Python 3.10+
- Flask: For the backend web server and routing.
- Requests: For sending POST requests to the Watson NLP API.
- HTML/JS/CSS: Frontend components.
- Watson NLP: The underlying AI model endpoint.
├── EmotionDetection/
│ ├── __init__.py
│ └── emotion_detection.py # Core logic for NLP API requests
├── static/
│ └── mywebscript.js # Frontend JavaScript for handling requests
├── templates/
│ └── index.html # Frontend HTML UI
├── server.py # Flask application entry point
├── test_emotion_detection.py # Unit tests for the application
└── README.md
-
Clone the repository:
git clone https://github.com/metalmancode/oaqjp-final-project-emb-ai.git cd oaqjp-final-project-emb-ai -
Install the dependencies: Make sure you have Python installed, then run:
pip install flask requests
-
Start the Flask server:
python3 server.py
-
Access the application: Open your web browser and go to
http://localhost:5000. -
Use the application: Enter text into the input field and click "Run Sentiment Analysis". The system will display the individual scores for each emotion and highlight the dominant one.
Expects a query parameter textToAnalyze.
- Example Request:
/emotionDetector?textToAnalyze=I%20love%20this%20new%20technology - Example Response:
For the given statement, the system response is 'anger': 0.01364663, 'disgust': 0.0017160787, 'fear': 0.008986978, 'joy': 0.9719017 and 'sadness': 0.055187024. The dominant emotion is joy.
The project includes unit tests to validate the emotion_detector function against predefined statements and their expected dominant emotions.
To run the tests, execute:
python3 test_emotion_detection.pyThe server.py file has been linted and optimized to meet a perfect 10.00/10 score on PyLint static code analysis.