Skip to content

Unleashing the Power of AI: Creating a Neural Network Powered Application

Notifications You must be signed in to change notification settings

trikoder/sentiment-analysis

Repository files navigation

Sentiment Analysis

Deploy your neural network locally with just a few easy commands!
We will use a pretrained sentiment analysis neural network from HuggingFace. To make things as easy as possible, we will download models from HuggingFace on container startup.

Prepare your environemnt

  1. Install Docker
  2. Clone this repository

Build Docker image

Position your shell in the root of this repository, and execute (be patient, some heavy packages are required :)

$ docker build -t sentiment_analysis .

Run Docker container

$ docker run --rm -it -p 8000:8000 sentiment_analysis

Advance Usage:

  • Set number of workers running inside a Docker container by adding a flag (default is 1): --env WORKERS=2 \
  • Change application port by adding flag (defalut is 8000), don't forget to change ports in docker run as well: --env PORT=8001
  • You can limit resource allocation for Docker container by adding these flags: --gpus "device=0" --cpus="2.0" --memory="4g"
    1. First flag gives access to GPU with ID=0. Without this flag, no GPUs are accessible inside docker container. If you want a container to have access to all GPUs on a system, write --gpus all. You must install additional Nvidia packages to allow GPU usage inside containers
    2. Second flag limits access to 2 CPU cores, without this flag container can use all CPU cores
    3. Third flag limits memory access to 4GB, without this flag container can use entire memory

Access API endpoints

API endpoints can be accessed, and are documented, here http://0.0.0.0:8000

Development

Install python3.11
For Debian based linux distributions:

$ sudo apt update
$ sudo apt install python3.11-full

Create 'venvs' folder if if doesn't exist

$ mkdir ~/.venvs

Create virtual environment

$ python3.11 -m venv ~/.venvs/sentiment-analysis

Activate a virtual environment

$ source ~/.venvs/sentiment-analysis/bin/activate

Format and check code

Install development packages

$ pip install -r requirements-dev.txt

Format and check code

$ isort . && black . && ruff --ignore E501 . && bandit -c bandit.yaml -rq . && mypy .

Install application packages locally

Install application packages

$ pip install -r requirements.txt

About

Unleashing the Power of AI: Creating a Neural Network Powered Application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published