Final Project for AI-Based Web Application Development and Deployment (Embeddable Watson AI). This app integrates the Watson NLP EmotionPredict API to analyze text and return five emotions (anger, disgust, fear, joy, sadness) plus the dominant emotion. Built with Flask.
- Watson NLP EmotionPredict integration (no local model required)
- Clean API wrapper with error handling (blank input → friendly message)
- Flask web UI (GET endpoint compatible with provided
index.html+mywebscript.js) - Unit tests for core behavior
- Passes Pylint static analysis (10/10 with docstrings)
emd_ai/
├─ EmotionDetection/
│ └─ emotion_detection.py # Core Watson API integration + error handling
│ └─ __init__.py # Core Watson API integration + error handling
├─ templates/
│ └─ index.html
├─ static/
│ └─ mywebscript.js
├─ server.py # Flask app (routes: / and /emotionDetector)
├─ tests/
│ └─ test_emotion_detection.py # Unit tests
├─requirements.txt
├─LICENSE
├─.gitignore
└─ README.md
Clone the repository:
git clone https://github.com/wkratos/emd_ai.git
cd emb_aiCreate and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateOn Windows PowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1Install the dependencies:
pip install -r requirements.txtpython3 server.pyApp runs on http://127.0.0.1:5000.
UI: open / to load index.html.
For the given statement, the system response is 'anger': 0.006, 'disgust': 0.003,
'fear': 0.009, 'joy': 0.968 and 'sadness': 0.049. The dominant emotion is joy.python3 -m unittest test_emotion_detection.pyor
python3 -m unittest tests/test_emotion_detection.pyor
python3 -m unittest discover -s testsExpected: all tests pass for dominant emotions:
-
glad → joy
-
mad → anger
-
disgusted → disgust
-
sad → sadness
-
afraid → fear
Blank or whitespace-only input → backend returns all None from the detector and the server responds with:
Invalid text! Please try again!
If the Watson endpoint returns 400, detector returns the same all-None structure by design.
pylint server.py-
Add module and function docstrings (already included)
-
Use snake_case function names
-
Avoid unused imports / long lines
Detector endpoint & headers
-
URL: https://sn-watson-emotion.labs.skills.network/v1/watson.runtime.nlp.v1/NlpService/EmotionPredict
-
Header: {"grpc-metadata-mm-model-id": "emotion_aggregated-workflow_lang_en_stock"}
-
Payload: {"raw_document": {"text": ""}}
Server routes
-
GET / → renders index.html
-
GET /emotionDetector?textToAnalyze= → returns formatted plain text