Flask API exposing an endpoint for determining the sentiment of text.
The following commands require execution in the project root.
- Create a virtual environment.
python3 -m venv .venv
- Activate the virtual environment.
. .venv/bin/activate
The following commands assume you have an active virtual environment.
- Install dependencies. (Using the Makefile)
make install
⚠ The above make
target
will install the latest, unpinned requirements from the file:requirements.in
. If encounter any dependency-related issue during installation or runtime, fall back to use tested, pinned, and stable requirements defined in the file:requirements.txt
- [Optional] Fall back to stable requirements.
pip install -r requirements.txt
- Run the application.
python app.py
- Query the api.
Query: I don't like this game
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"input": "I don't like this game"}' \
"http://127.0.0.1:10010/api/v1/sentiment"
Output:
{
"prediction": {
"confidence": 0.9779077172279358,
"label": "Negative"
}
}
-
Prerequisite: Make sure you have docker installed. Link
-
Build the docker image. This uses the Docker file in the repository's root.
docker build --build-arg VERSION=SENTIMENT-v1 -t sentiment-api:dev .
- Run a container using the image as its base.
docker run --rm -p 10010:10010 --name sentiment-api sentiment-api:dev
-
Querying works like the previous one. You can also use Postman.
-
More Examples:
Query: I like this game
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"input": "I like this game"}' \
"http://127.0.0.1:10010/api/v1/sentiment"
{
"prediction": {
"confidence": 0.9681828022003174,
"label": "Positive"
}
}
Query: I have no opinion
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"input": "I have no opinion"}' \
"http://127.0.0.1:10010/api/v1/sentiment"
{
"prediction": {
"confidence": 0.49172118306159973,
"label": "Neutral"
}
}
- Code available in branches
deploy
forAWS Lightsail
andebs
forAWS Elasticbeanstalk
. - Documentations are available via this link, Pages
8
&9
.
Built with ❤️ by martinoywa.