Rest-API for englisch sentiment analysis of an input text.
Create a new venv (virtual environment):
python3 -m venv .venvActivate new environment:
For Mac/Linux:
source .venv/bin/activateFor Windows:
source .venv/Scripts/activateInstall packages:
pip install -r requirements.txtDownload the model:
python -m app.save_model
API_KEY=CHANGE_ME uvicorn app.main:app --reloadThe server is running on http://localhost:8000.You can change the API_KEY if you like. Swagger documentation can be accessed at http://localhost:8000/docs.
To send a request via your terminal, paste & run the following command:
curl -X POST -H 'Content-type: application/json' -H 'X-API-Key: CHANGE_ME' --data '{"text":"Hello, World!"}' http://localhost:8000docker build -t sentiment-api-en .Run the Docker Image with:
docker run -d --rm -p 8000:80 --env API_KEY=CHANGE_ME --name sentiment-api-en sentiment-api-enYou can now access the api at http://localhost:8000. Swagger documentation are available at http://localhost:8000/docs.
To view the logs of the container run:
docker logs sentiment-api-enTo stop the container run:
docker stop sentiment-api-enYou can spin up the setup using docker compose and benefit e.g. from automatic server restarts. Before running the setup, please change the environment variable in the docker-compose.yml file. Then run:
docker compose up -dTo stop the setup you can run
docker compopse down
To rebuild the docker image run
docker compose build
Logs can be accessed with
docker compose logs