This README provides an overview of the internals of this API using FastAPI, Celery, and Redis. FastAPI is a modern, fast web framework for building APIs with Python. Celery is a distributed task queue for processing asynchronous tasks. Redis is used as the backend for Celery, storing task states and results.
- BunkaTopics API built upon FastAPI with Celery and Redis
- Docker
- Make
- Nginx
- Copy .env.model to .env
- Create the Docker shared network:
make docker_create_network
- Install GPU toolkit for python containerized code to use it, OR use an VPS Ubuntu Image with NVIDIA cuda already baked in (we advice you to use this last option)
Here's a simple guide to install the NVIDIA GPU Toolkit on an Ubuntu server:
This guide outlines the steps to install the NVIDIA GPU Toolkit (CUDA) on an Ubuntu server, enabling TensorFlow and other Python libraries to access the GPU.
- Ensure your NVIDIA GPU is compatible with the CUDA version you plan to install.
-
Open a terminal and update your Ubuntu package lists:
sudo apt-get update sudo apt-get upgrade
- Go to the NVIDIA CUDA Downloads page and select the appropriate version for your Ubuntu server.
- Download the debian (network) installer and follow the instructions on their website.
-
Nouveau (default Linux GPU driver) can interfere with NVIDIA drivers. To disable:
sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf" sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf" sudo update-initramfs -u
- User: Interacts with the FastAPI application through HTTP requests.
- FastAPI Application: Receives HTTP requests from the user. For asynchronous tasks, it sends task requests to the Celery worker queue and provides immediate responses (like task IDs) back to the user. -Celery Worker Queue: Receives task requests from the FastAPI application. It queues these tasks and processes them asynchronously. The status and results of these tasks are managed using Redis.
- Redis: Acts as a message broker and a result backend for Celery. It stores the task queue and the states/results of tasks processed by the Celery workers.
User Request
β
ββββ> FastAPI Application ββββββ> Celery Worker Queue ββββ> Redis
β β
β<βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββ> Status/Result Query
-
User Request: The user sends a request to the FastAPI application (e.g., to process data, start a background job, etc.).
-
FastAPI Processes Request: FastAPI processes the request. If it's an asynchronous task, FastAPI sends this task to the Celery worker queue and returns a response (like a task ID) to the user.
-
Task Queuing in Redis: The task is queued in Redis by the Celery worker.
-
Task Processing: The Celery worker processes the task. The status and result of the task are updated in Redis.
-
Result Retrieval: The user can query the FastAPI application for the status or result of the task, which FastAPI retrieves from Redis via the Celery worker.
Run both API and Celery worker with Docker using the Makefile at the root of this repository
- Start a redis docker :
make docker_run_redis
- Configure Nginx reverse proxy:
make install_nginx_config
(this uses a Nginx started on your host, not a container) - Build both docker:
make build_docker && make build_docker_worker
- Run both docker:
make run_docker && make run_docker_worker
Type hostname in your *NIX terminal to print your hostname Go to http:https://[$hostname] or http:https://localhost
- Via git:
git clone https://github.com/charlesdedampierre/BunkaTopics.git
cd BunkaTopics
git pull # only for an existing clone
- Then repeat the process for running the application described above
- The complete API documentation and playground is available at
http:https://[$hostname]/api/docs
- Celery worker is in solo mode, so the NLP processing tasks run in band.
- Log tasks :
docker logs -f bunkaworker
- Log API :
docker logs -f bunkaapi
- TODO : add user authentication and let them save theirs projects and maps.
- Security considerations : run your server behind a password.
- Look for Docker, FastAPI, Celery, and Redis documentation for common issues and their solutions.