API for detecting language 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.txtAPI_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 language-detection-api .Run the Docker Image with:
docker run -d --rm -p 8000:80 --env API_KEY=CHANGE_ME --name language-detection-api language-detection-apiYou 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 language-detection-apiTo stop the container run:
docker stop language-detection-apiYou 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