Open Platform For Enterprise AI Avatar Chatbot Creation
How may an AI avatar chatbot be created using theĀ Open Platform For Enterprise AIĀ framework?
The graph displays the applicationās overall flow. TheĀ Open Platform For Enterprise AIĀ GenAIExamples repositoryās āAvatar Chatbotā serves as the code sample. The āAvatarChatbotā megaservice, the applicationās central component, is highlighted in the flowchart diagram. Four distinct microservices Automatic Speech Recognition (ASR),Ā Large Language Model (LLM), Text-to-Speech (TTS), and Animation are coordinated by the megaservice and linked into a Directed Acyclic Graph (DAG).
Every microservice manages a specific avatar chatbot function. For instance:
Software for voice recognition that translates spoken words into text is called Automatic Speech Recognition (ASR).
By comprehending the userās query, the Large Language Model (LLM) analyzes the transcribed text from ASR and produces the relevant text response.
The text response produced by the LLM is converted into audible speech by a text-to-speech (TTS) service.
The animation service makes sure that the lip movements of the avatar figure correspond with the synchronized speech by combining the audio response from TTS with the user-defined AI avatar picture or video. After then, a video of the avatar conversing with the user is produced.
An audio question and a visual input of an image or video are among the user inputs. A face-animated avatar video is the result. By hearing the audible response and observing the chatbotās natural speech, users will be able to receive input from the avatar chatbot that is nearly real-time.
Create the āAnimationā microservice in the GenAIComps repository
We would need to register a newĀ microservice, such āAnimation,ā under comps/animation in order to add it:
Register the microservice
@register_microservice(
name=āopea_service@animationā,
service_type=ServiceType.ANIMATION,
endpoint=ā/v1/animationā,
host=ā0.0.0.0ā³,
port=9066,
input_datatype=Base64ByteStrDoc,
output_datatype=VideoPath,
)
@register_statistics(names=[āopea_service@animationā])
It specify the callback function that will be used when this microservice is run following the registration procedure. The āanimateā function, which accepts a āBase64ByteStrDocā object as input audio and creates a āVideoPathā object with the path to the generated avatar video, will be used in the āAnimationā case. It send an API request to the āwav2lipā FastAPIās endpoint from āanimation.pyā and retrieve the response in JSON format.
Remember to import it in comps/init.py and add the āBase64ByteStrDocā and āVideoPathā classes in comps/cores/proto/docarray.py!
This link contains the code for the āwav2lipā server API. Incoming audio Base64Str and user-specified avatar picture or video are processed by the post function of this FastAPI, which then outputs an animated video and returns its path.
The functional block for its microservice is created with the aid of the aforementioned procedures. It must create a Dockerfile for the āwav2lipā server API and another for āAnimationā to enable the user to launch the āAnimationā microservice and build the required dependencies. For instance, the Dockerfile.intel_hpu begins with the PyTorch* installer Docker image forĀ Intel GaudiĀ and concludes with the execution of a bash script called āentrypoint.ā
Create the āAvatarChatbotā Megaservice in GenAIExamples
The megaservice class AvatarChatbotService will be defined initially in the Python file āAvatarChatbot/docker/avatarchatbot.py.ā Add āasr,ā āllm,ā ātts,ā and āanimationā microservices as nodes in aĀ Directed Acyclic Graph (DAG)Ā using the megaservice orchestratorās āaddā function in the āadd_remote_serviceā function. Then, use the flow_to function to join the edges.
Specify megaserviceās gateway
An interface through which users can access the Megaservice is called a gateway. The Python file GenAIComps/comps/cores/mega/gateway.py contains the definition of the AvatarChatbotGateway class. The host, port, endpoint, input and output datatypes, and megaservice orchestrator are all contained in the AvatarChatbotGateway. Additionally, it provides a handle_request function that plans to send the first microservice the initial input together with parameters and gathers the response from the last microservice.
In order for users to quickly build the AvatarChatbot backend Docker image and launch the āAvatarChatbotā examples, we must lastly create a Dockerfile. Scripts to install required GenAI dependencies and components are included in the Dockerfile.
II. Face Animation Models and Lip Synchronization
A state-of-the-art lip-synchronization method that uses deep learning to precisely match audio and video is Wav2Lip. Included in Wav2Lip are:
A skilled lip-sync discriminator that has been trained and can accurately identify sync in actual videos
A modified LipGAN model to produce a frame-by-frame talking face video
An expert lip-sync discriminator is trained using the LRS2 dataset as part of the pretraining phase. To determine the likelihood that the input video-audio pair is in sync, the lip-sync expert is pre-trained.
A LipGAN-like architecture is employed during Wav2Lip training. A face decoder, a visual encoder, and a speech encoder are all included in the generator. Convolutional layer stacks make up all three. Convolutional blocks also serve as the discriminator. The modified LipGAN is taught similarly to previous GANs: the discriminator is trained to discriminate between frames produced by the generator and the ground-truth frames, and the generator is trained to minimize the adversarial loss depending on the discriminatorās score. In total, a weighted sum of the following loss components is minimized in order to train the generator:
A loss of L1 reconstruction between the ground-truth and produced frames
A breach of synchronization between the lip-sync expertās input audio and the output video frames
Depending on the discriminator score, an adversarial loss between the generated and ground-truth frames
After inference, it provide the audio speech from the previous TTS block and the video frames with the avatar figure to the Wav2Lip model. The avatar speaks the speech in a lip-synced video that is produced by the trained Wav2Lip model.
Lip synchronization is present in the Wav2Lip-generated movie, although the resolution around the mouth region is reduced. To enhance the face quality in the produced video frames, it might optionally add a GFPGAN model after Wav2Lip. The GFPGAN model uses face restoration to predict a high-quality image from an input facial image that has unknown deterioration. A pretrained face GAN (like Style-GAN2) is used as a prior in this U-Net degradation removal module. A more vibrant and lifelike avatar representation results from prettraining the GFPGAN model to recover high-quality facial information in its output frames.
It provides another cutting-edge model option for facial animation in addition to Wav2Lip. The 3D motion coefficients (head, stance, and expression) of a 3D Morphable Model (3DMM) are produced from audio by SadTalker, a stylized audio-driven talking-head video creation tool. The input image is then sent through a 3D-aware face renderer using these coefficients, which are mapped to 3D key points. A lifelike talking head video is the result.
Intel made it possible to use the Wav2Lip model onĀ Intel Gaudi Al acceleratorsĀ and the SadTalker and Wav2Lip models on Intel Xeon Scalable processors.
Read more on Govindhtech.com