Skip to content

stackOcean-official/language-detection-api

Repository files navigation

language-detection-api

API for detecting language of an input text

How to setup

Create a new venv (virtual environment):

python3 -m venv .venv

Activate new environment:

For Mac/Linux:

source .venv/bin/activate

For Windows:

source .venv/Scripts/activate

Install packages:

pip install -r requirements.txt

Run the server

API_KEY=CHANGE_ME && uvicorn app.main:app --reload

The 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:8000

How to build & run the Docker Image

docker 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-api

You 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-api

To stop the container run:

docker stop language-detection-api

How to use docker compose

You 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 -d

To 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

About

API for detecting language of an input text

Resources

License

Stars

Watchers

Forks

Releases

No releases published