Solidus AITECH

AI Marketplace Docs

Architecture overview

1.1 Overview

Figure 1: AI app architecture overview

Figure 1: AI app architecture overview

Table 1. Describe component in AI service architecture

No.CategoryComponentDescriptionAI scopeNote
1ClientClientAI marketplaceN
2Client callbackClient callbackGet results after a task has been completedN
3AI App APIAI App APIReceive request from client (marketplace) and process. Manage stages to solve a specific task.Y
4StorageS3 storageStore media data (Including request data from the client and AI result data). Services send media file metadata to each otherN
5AI APP DatabaseStore user request information for statisticsY
6RedisStore temporary results of tasks and requests: Will be deleted after a period of timeY
7QueueRabbitMQStore pending tasksY
8AI service 1AI service 1 APIReceive requests to process tasks and push tasks into the queueY
9AI service workerPull the task in the queue and process itY
10AI service 2AI service 2 APIReceive requests to process tasks and push tasks into the queueOptionalWhether or not depends on the AI ​​problem
11AI service workerPull the task in the queue and process itOptionalWhether or not depends on the AI ​​problem

With a basic AI problem: AI service will require a minimum of 6 components (docker container). The number of components will increase when the AI ​​problem is complex and needs to be divided into multiple stages for processing

Examples for simple AI problems: Person detection, face detection, face embedding, face searching… For each problem like this, 6 components need to be developed and deployed

For more complex problems such as face recognition, it needs to be processed through many steps: face detection, then face embedding and finally searching. There are up to 3 stages in this problem, so there will be up to 3 AI services. Therefore, the number of components that need to be developed and deployed is 10 (add 2 components for each added service)

1.2 AudioCraft service

Audio Craft is an AI service that generates sounds and music based on user descriptions. It is divided into 2 sub-services that operate independently of each other. The AudioGen is used for generating sounds such as: car horns, cat meowing... and the MusicGen specializes in generating music (with melody). AudioCraft's system design is shown in the figure 2

Figure 2: AudioCraft architecture

Figure 2: AudioCraft architecture

Figure 3: Call API sequence diagram

Figure 3: Call API sequence diagram

Table 2. Description of sequence diagram and executable code in source code

No.DescriptionExecutable codeNote
1.1Client create a request to AI service

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:call

Line number: 198

1.2Service validation

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:call

Line number: 205

1.3Create workflow with workflow_id (task_id)

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:call:

Line number: 223

1.4Response to client status of request

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:call:

Line number: 227

1.5Sen request to AudioGen API

Module: app_api.app_api

Class:AudioCraftWorkFlow

Function:trigger_request_text2audio:

Line number: 132

1.6Create a task and push to task queue

Module: audio_core_api.audio_core_api

Class:AudioGenerationAPI

Function:api_generate_audio

Line number: 66

1.7AudioGen worker pull task and perform

Module: audio_core_api.audio_gen_worker

Class:AudioGenerationSerivce

Function:run

Line number: 28

1.8Execute callback

Module: audio_core_api.audio_gen_worker

Class:AudioGenerationSerivceCallback

Function:run

Line number: 104

1.9Store media file on S3 storage

Module: audio_core_api.audio_gen_worker

Class:AudioGenerationSerivce

Function:run

Line number: 54

1.10Store temporary result on Redis

Module: audio_core_api.audio_gen_worker

Class:AudioGenerationSerivce

Function:run

Line number: 74

1.11Aggregate final result

Module: app_api.app_api

Class:AudioCraftWorkFlow

Function:trigger_text2audio_callback

Line number: 145

1.12Store final result on Redis

Module: app_api.app_api

Class:AudioCraftWorkFlow

Function:trigger_text2audio_callback

Line number: 147

1.13Store request information in database

Module: app_api.app_api

Class:AudioCraftWorkFlow

Function:process_result

Line number: 103

1.14Execute client callback

Module: app_api.app_api

Class:AudioCraftWorkFlow

Function:process_result

Line number: 94

Figure 4: Result API sequence diagram

Figure 4: Result API sequence diagram

Table 3. Description of sequence diagram and executable code in source code

No.DescriptionExecutable codeNote
2.1Client create a request to to get result based on task_id

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:result

Line number: 235

2.2Service validation

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:result

Line number: 238

2.3Retrieve workflow based on task_id (workflow uuid)

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:result

Line number: 258

2.4Get URL in S3

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:result

Line number: 266

2.5Response result to client

Module: app_api.app_api

Class:AudioCraftAppAPI

Function:result

Line number: 288

Figure 5: Stats API sequence diagram

Figure 5: Stats API sequence diagram

Table 4. Description of sequence diagram and executable code in source code

No.DescriptionExecutable codeNote
3.1Client creates a request to get statistical information

Module: aimarket_core_app_base.app

Class: BaseAppAPI

Function: stats

Line number: 112

3.2Service validation

Module: aimarket_core_app_base.app

Class: BaseAppAPI

Function: stats

Line number: 112

3.3Query data in database

Module: aimarket_core_app_base.app

Class: BaseAppAPI

Function: get_results_by_user_id

Line number: 117

3.4Response result to client

Module: aimarket_core_app_base.app

Class: BaseAppAPI

Function: stats

Line number: 120

2. Package

2.1 Docker image

No.ComponentDocker image nameType
1RabbitMQrabbitmq:3.8.14-management-alpineOpensource
2Redisredis:6-alpine
3AI APP databasepostgres:12-alpine
4AI APP APIyour_registry_url/your_repo:versionSelf-build
5AudioGen API
6AudioGen worker
7MusicGen API
8MusicGen worker

2.2 Build docker image

Step 1: Clone the project

$ git clone https://github.com/DopikAI-Labs/aimarket-audiocraft-service.git
# The Git repository URL may change when delivering the source code to the customer. Carefully check the provided URL.

Step 2: Update submodule

$ cd aimarket-audiocraft-service
$ submodule update --init --recursive

If the source code provided is a compressed file, skip the above two steps

Step 3: Build image

Edit script: ./scripts/build_dockerfile.sh

Update the ECR, and version in ./version.json

#!/bin/bash

ECR="your_registry_url/your_repo"
TAG=$(jq -r '.api_version' version.json)
SERVICE="audio_craft"
IMAGE_NAME="${ECR}:${SERVICE}_${TAG}"

docker build -t $IMAGE_NAME -f dockerfile .
echo  image $IMAGE_NAME is built
$ cd aimarket-audiocraft-service

Build image

$ chmod +x ./scripts/build_dockerfile.sh
$ ./scripts/build_dockerfile.sh

If no errors occur, the terminal will show

$ your_registry_url/your_repo:audio_craft_0.1.4 is built

Step 4: Push image to registry

Step 4.1: Login to registry

Install awscli

$ pip install awscli
# or pip3 install awscli
# If you're using a virtual environment created with venv or conda, make sure it's activated before proceeding.

Configure AWS information

$ aws configure
# AWS Access Key ID [None]: Enter your access key ID
# AWS Secret Access Key [None]: Enter your secret  access key 
# Default region name [None]: Enter region
# Default output format [None]: Can skip it

For the next time, there is no need to do the above 2 steps in step 4.1 section

Get the password

$ aws ecr get-login-password
# The terminal will generate a string (password)

Login repository: Make sure repository has been created

$ docker login -u AWS -p <<generated_string_from_above_command>> <<repository_URL_in_ECR>>

Step 4.2: Push docker image

Push docker image

$ docker push docker_image_name:tag

3. Deployment

3.1 Infrastructure requirements

No.CategoryItemRequired
1HardwareCPU
2CPU archx64
3RAM16G
4NVIDIA GPU12GB
5Storage (root)32GB
6SoftwareOSUbuntu 20.04 or later
7Docker26.x.x or later
8Docker-compose1.29.x or later

3.2 Deployment procedure

Step 1: Pull docker image

Step 1.1 Login registry

Do the same as step 4.1 in the package section

Step 1.2 Pull image

$ docker pull docker_image_name:tag
# docker_image_name:tag => It is an pushed image in the package section 

Step 2: Deploy service

Make a deployment directory

$ cd ../../../deployment_space_dirctory_path
$ mkdir audio_craft
$ cd audio_craft
$ mkdir v0.1.4
$ cd v0.1.4
# v0.1.4: Change to match the version to be deployed

Create a docker-compose.yml file

$ vim docker-compose.yml 
# Copy ./aimarket-audiocraft-service/docker-compose.yml and past to it

Create .env file

$ vim .env 
# Copy ./aimarket-audiocraft-service/.env and past to it

With the .env file, all environment variables highlighted in red need to be updated.

No.GroupVariableDefault valueRequired update
1AI ServiceAPP_API_PORT8007Y
2AUDIO_GEN_PORT8081Optional
3MUSIC_GEN_PORT8082Optional
4MAX_DURATION30Optional
5MAX_PROMPT_LEN100Optional
6CACHE_MODEL_DIR../model_hubNO
7TRANSFORMERS_CACHE/model_hubNO
8AUDIOCRAFT_CACHE_DIR/model_hubNO
9AUDIO_GEN_MODELfacebook/audiogen-mediumOptional
10MUSIC_GEN_MODELfacebook/musicgen-smallOptional
11API_VERSION0.1.4Optional
12API_NAMEAudioCraftOptional
13DatabasePOSTGRES_USERaimarketAdminOptional
14POSTGRES_PASSWORDaimarketPasswordOptional
15POSTGRES_DBaimarketDbOptional
16S3 storageAWS_REGION_NAME<<SECRET>>Y
17AWS_ACCESS_KEY<<SECRET>>Y
18AWS_SECRET_KEY<<SECRET>>Y
19RabbitMQRABBITMQ_HOSTaimarket_rabbitmqOptional
20RABBITMQ_VHOSTaiqrbrokerOptional
21RABBITMQ_USERaiqradminOptional
22RABBITMQ_PASSaiqrPasswordOptional
23RABBITMQ_PORT5672Optional
24RABBITMQ_UI_PORT15672Optional
25RedisREDIS_HOSTaimarket_redisOptional
26REDIS_PORT6379Optional
27REDIS_DB_NAME0Optional
28MarketPlaceMARKETPLACE_TOKEN<<SECRET>>Y
29MARKETPLACE_CALLBACK<<SECRET>>Y

Run service

# make sure you are in the same directory with docker-compose.yml file
$ docker-compose up

Check the terminal to determine if any errors occurred. If not, Ctrl + C to stop running service

Run service in detached mode

$ docker-compose up -d