Skip to content

metalmancode/Emotion_Detection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Final project: Emotion Detection Application

Overview

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.

Features

  • 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.

Technologies Used

  • 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.

Project Structure

├── 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

Setup and Installation

  1. Clone the repository:

    git clone https://github.com/metalmancode/oaqjp-final-project-emb-ai.git
    cd oaqjp-final-project-emb-ai
  2. Install the dependencies: Make sure you have Python installed, then run:

    pip install flask requests

How to Run

  1. Start the Flask server:

    python3 server.py
  2. Access the application: Open your web browser and go to http://localhost:5000.

  3. 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.

API Endpoint

GET /emotionDetector

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.

Testing

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.py

Code Quality

The server.py file has been linted and optimized to meet a perfect 10.00/10 score on PyLint static code analysis.

About

final-project-emb-ai

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 69.4%
  • HTML 22.7%
  • JavaScript 7.9%