benedictchuajj / emotion-docker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

emotion-docker

Configuration for the docker container of some emotion recognition and sentiment analysis models from HuggingFace. The emotion recognition model is a fine-tuned version of a pre-trained model to simplify the number of emotions detected to be relevant to my use-case (analyzing messages to a chatbot).

Prerequisites

Make sure you have the following installed:

  • Python 3.10
  • Pip (Python package installer)

Installation

  1. Clone the repository:

    git clone https://github.com/benedictchuajj/emotion-docker.git
  2. Change into the project directory:

    cd emotion-docker
  3. Download the zipped folder containing the emotion and sentiment models from Teams, and unzip it in this directory

Usage (Local)

  1. Build the docker image:

    docker build -t emotion .

    Note: If you are rebuilding the images several times, make sure to delete the older images as each image is around 8GB

  2. Run the image in a container:

    docker run -p 9000:8080 emotion

    This runs the docker image locally as a container on local port 9000, where 8080 is the container port.

  3. Open a separate terminal and invoke the main function of the container:

    curl --request POST \           
    --url http://localhost:9000/2015-03-31/functions/function/invocations \
    --header 'Content-Type: application/json' \
    --data '{"sentence": "nice to meet you, my name is bob :)"}'

    You should receive an output similar to the following

    {"statusCode": 200, 
    "sentiment_score": 0.7384703792631626, 
    "emotion": "joy", 
    "top5_emotions": [
        {"name": "joy", "value": 0.5143717527389526}, 
        {"name": "others", "value": 0.169914111495018}, 
        {"name": "anger", "value": 0.1594364047050476}, 
        {"name": "sadness", "value": 0.15627767145633698}
    ]}

Usage (AWS Lambda)

Follow the instructions in AWS docs to upload the docker image in Amazon ECR which can then be created into a Lambda function.

About

License:Apache License 2.0


Languages

Language:Python 92.7%Language:Dockerfile 7.3%