Sign inSign up

lbrenman/apib_detectsentiment

By lbrenman

•Updated over 4 years ago

An API Builder API to detect the sentiment in text using AWS Comprehend

Image
API management
0

1.0K

lbrenman/apib_detectsentiment repository overview

⁠Docker Hub Readme

A sentiment analysis natural language processing API example based on API Builder. Project can be found here⁠ on Github. The API leverages AWS Comprehend⁠.

The API is an example of an API First API designed in Stoplight and Built in API Builder as described in the following blog post:

The API is shown below:

GET /detectSentiment?text=this%20is%20great

and accepts the text to be analyzed as query parameter, "text".

It returns the sentiment of the text:

{
  "Sentiment": "POSITIVE",
  "SentimentScore": {
    "Positive": 0.9985805749893188,
    "Negative": 0.00013431961997412145,
    "Neutral": 0.0008679831516928971,
    "Mixed": 0.00041714494000189006
  }
}

The API uses API Key authentication that is passed in a header with key apikey.

The container requires three env vars:

  • API_KEY - a randomly selected API Key that you can provide that is used to authenticate API calls in a header with key apikey
  • AWS_ACCESS_KEY_ID - AWS Access Key
  • AWS_SECRET_ACCESS_KEY - AWS Secret Key

You can read about AWS credentials here⁠.

You can run the container locally using the following commands:

docker run --name apib_detectsentiment -e API_KEY=<API KEY YOU PROVIDE> -e AWS_ACCESS_KEY_ID=<YOUR AWS ACCESS KEY> -e AWS_SECRET_ACCESS_KEY=<YOUR AWS SECRET> -p 8080:8080 --rm lbrenman/apib_detectsentiment:latest

curl -is -H "accept: application/json" -H "apikey: <API KEY YOU PROVIDE>" -X GET "http://localhost:8080/api/detectSentiment?text=Das%20ist%20nicht%20gut"

Response:

{
  "Sentiment": "NEGATIVE",
  "SentimentScore": {
    "Positive": 0.00007716986874584109,
    "Negative": 0.999670147895813,
    "Neutral": 0.00024405473959632218,
    "Mixed": 0.000008644425179227255
  }
}

Tag summary

Content type

Image

Digest

Size

79.2 MB

Last updated

over 4 years ago

docker pull lbrenman/apib_detectsentiment