Skip to content

Commit c26d37e

Browse files
ctao456hteeyeohXinyuYe-Intelpre-commit-ci[bot]ZePan110
authored
Initiate "animation" component (#775)
* updates needed for demo Signed-off-by: Chun Tao <chun.tao@intel.com> * original pr content Signed-off-by: Chun Tao <chun.tao@intel.com> * Revert "updates needed for demo" This reverts commit f0c7a02. Signed-off-by: Chun Tao <chun.tao@intel.com> * remove improper images Signed-off-by: Chun Tao <chun.tao@intel.com> * Addressed some comments on previous pr Signed-off-by: Chun Tao <chun.tao@intel.com> * Add Dockerfile for cpu support Signed-off-by: Chun Tao <chun.tao@intel.com> * CODEOWNER: Update comp CODEOWNER (#757) Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> Signed-off-by: Chun Tao <chun.tao@intel.com> * Add stable diffusion microservice (#729) * add stable diffusion microservice. Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com> * added test. Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com> * changed output to images bytes data Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * unified inference and wrapper into one microservice. Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix test. Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com> --------- Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Chun Tao <chun.tao@intel.com> * Compatible with different platforms. (#766) * Compatible with different platforms. Signed-off-by: ZePan110 <ze.pan@intel.com> * Fix issue. Signed-off-by: ZePan110 <ze.pan@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix issue Signed-off-by: ZePan110 <ze.pan@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: ZePan110 <ze.pan@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Chun Tao <chun.tao@intel.com> * Optimize path and link validity check. (#745) Signed-off-by: ZePan110 <ze.pan@intel.com> Signed-off-by: Chun Tao <chun.tao@intel.com> * Add timeout for ut test (#773) Signed-off-by: chensuyue <suyue.chen@intel.com> Signed-off-by: Chun Tao <chun.tao@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: Chun Tao <chun.tao@intel.com> * test hyperlink Signed-off-by: Chun Tao <chun.tao@intel.com> * test hyperlink Signed-off-by: Chun Tao <chun.tao@intel.com> * test hyperlink issue Signed-off-by: Chun Tao <chun.tao@intel.com> * test hyperlink issue Signed-off-by: Chun Tao <chun.tao@intel.com> * put back hyperlinks in readme Signed-off-by: Chun Tao <chun.tao@intel.com> * remove possible error hyperlink Signed-off-by: Chun Tao <chun.tao@intel.com> * put hyperlink back Signed-off-by: Chun Tao <chun.tao@intel.com> * major update to use FastAPI for wav2lip, and structure component format Signed-off-by: Chun Tao <chun.tao@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add dockerfiles in animation-compose-cd.yaml Signed-off-by: Chun Tao <chun.tao@intel.com> * Fix end of file issue in animation-compose-cd.yaml Signed-off-by: Chun Tao <chun.tao@intel.com> * Fix Docker deployment on Xeon Signed-off-by: Chun Tao <chun.tao@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add versioning for all pip packages Signed-off-by: Chun Tao <chun.tao@intel.com> * e2e test script for animation Signed-off-by: Chun Tao <chun.tao@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update e2e test script Signed-off-by: Chun Tao <chun.tao@intel.com> * update e2e test script Signed-off-by: Chun Tao <chun.tao@intel.com> * update readme Signed-off-by: Chun Tao <chun.tao@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update Signed-off-by: Chun Tao <chun.tao@intel.com> * update Signed-off-by: Chun Tao <chun.tao@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update gateway Signed-off-by: Chun Tao <chun.tao@intel.com> * udpate gateway Signed-off-by: Chun Tao <chun.tao@intel.com> * Fix AVATAR_CHATBOT Signed-off-by: Chun Tao <chun.tao@intel.com> * update gateway Signed-off-by: Chun Tao <chun.tao@intel.com> * update Signed-off-by: Chun Tao <chun.tao@intel.com> * test Signed-off-by: Chun Tao <chun.tao@intel.com> * update Signed-off-by: Chun Tao <chun.tao@intel.com> * update Signed-off-by: Chun Tao <chun.tao@intel.com> * update gateway Signed-off-by: Chun Tao <chun.tao@intel.com> * fix max_tokens in AvatarChatbot gateway Signed-off-by: Chun Tao <chun.tao@intel.com> * test Signed-off-by: Chun Tao <chun.tao@intel.com> * update Signed-off-by: Chun Tao <chun.tao@intel.com> * update Signed-off-by: Chun Tao <chun.tao@intel.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Chun Tao <chun.tao@intel.com> Signed-off-by: Yeoh, Hoong Tee <hoong.tee.yeoh@intel.com> Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com> Signed-off-by: ZePan110 <ze.pan@intel.com> Signed-off-by: chensuyue <suyue.chen@intel.com> Co-authored-by: Hoong Tee, Yeoh <hoong.tee.yeoh@intel.com> Co-authored-by: XinyuYe-Intel <xinyu.ye@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: ZePan110 <ze.pan@intel.com> Co-authored-by: chen, suyue <suyue.chen@intel.com>
1 parent f6c3a82 commit c26d37e

33 files changed

Lines changed: 1182 additions & 0 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# this file should be run in the root of the repo
5+
# images used by GenAIExamples: animation, wav2lip, wav2lip-gaudi
6+
services:
7+
animation:
8+
build:
9+
dockerfile: comps/animation/wav2lip/Dockerfile
10+
image: ${REGISTRY:-opea}/animation:${TAG:-latest}
11+
wav2lip:
12+
build:
13+
dockerfile: comps/animation/wav2lip/dependency/Dockerfile
14+
image: ${REGISTRY:-opea}/wav2lip:${TAG:-latest}
15+
wav2lip-gaudi:
16+
build:
17+
dockerfile: comps/animation/wav2lip/dependency/Dockerfile.intel_hpu
18+
image: ${REGISTRY:-opea}/wav2lip-gaudi:${TAG:-latest}

comps/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
VideoQnAGateway,
5959
VisualQnAGateway,
6060
MultimodalQnAGateway,
61+
AvatarChatbotGateway,
6162
)
6263

6364
# Telemetry

comps/animation/wav2lip/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Use a base image
5+
FROM python:3.11-slim
6+
7+
RUN useradd -m -s /bin/bash user && \
8+
mkdir -p /home/user && \
9+
chown -R user /home/user/
10+
USER user
11+
12+
ENV LANG=C.UTF-8
13+
ARG ARCH=cpu
14+
15+
COPY comps /home/user/comps
16+
17+
RUN pip install --no-cache-dir --upgrade pip && \
18+
pip install --no-cache-dir -r /home/user/comps/animation/wav2lip/requirements.txt ;
19+
20+
ENV PYTHONPATH=$PYTHONPATH:/home/user
21+
22+
WORKDIR /home/user/comps/animation/wav2lip
23+
24+
ENTRYPOINT ["python3", "animation.py"]

comps/animation/wav2lip/README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Avatar Animation Microservice
2+
3+
The avatar animation model is a combination of two models: Wav2Lip and GAN-based face generator (GFPGAN). The Wav2Lip model is used to generate lip movements from an audio file, and the GFPGAN model is used to generate a high-quality face image from a low-quality face image. The avatar animation microservices takes an audio piece and a low-quality face image/video as input, fuses mel-spectrogram from the audio with frame(s) from the image/video, and generates a high-quality video of the face image with lip movements synchronized with the audio.
4+
5+
# 🚀1. Start Microservice with Docker (option 1)
6+
7+
## 1.1 Build the Docker images
8+
9+
### 1.1.1 Wav2Lip Server image
10+
11+
```bash
12+
git clone https://github.com/opea-project/GenAIComps.git
13+
cd GenAIComps
14+
```
15+
16+
- Xeon CPU
17+
18+
```bash
19+
docker build -t opea/wav2lip:latest -f comps/animation/wav2lip/dependency/Dockerfile .
20+
```
21+
22+
- Gaudi2 HPU
23+
24+
```bash
25+
docker build -t opea/wav2lip-gaudi:latest -f comps/animation/wav2lip/dependency/Dockerfile.intel_hpu .
26+
```
27+
28+
### 1.1.2 Animation server image
29+
30+
```bash
31+
docker build -t opea/animation:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/animation/wav2lip/Dockerfile .
32+
```
33+
34+
## 1.2. Set environment variables
35+
36+
- Xeon CPU
37+
38+
```bash
39+
export ip_address=$(hostname -I | awk '{print $1}')
40+
export DEVICE="cpu"
41+
export WAV2LIP_PORT=7860
42+
export ANIMATION_PORT=9066
43+
export INFERENCE_MODE='wav2lip+gfpgan'
44+
export CHECKPOINT_PATH='/usr/local/lib/python3.11/site-packages/Wav2Lip/checkpoints/wav2lip_gan.pth'
45+
export FACE="comps/animation/wav2lip/assets/img/avatar1.jpg"
46+
# export AUDIO='assets/audio/eg3_ref.wav' # audio file path is optional, will use base64str in the post request as input if is 'None'
47+
export AUDIO='None'
48+
export FACESIZE=96
49+
export OUTFILE="comps/animation/wav2lip/assets/outputs/result.mp4"
50+
export GFPGAN_MODEL_VERSION=1.4 # latest version, can roll back to v1.3 if needed
51+
export UPSCALE_FACTOR=1
52+
export FPS=10
53+
```
54+
55+
- Gaudi2 HPU
56+
57+
```bash
58+
export ip_address=$(hostname -I | awk '{print $1}')
59+
export DEVICE="hpu"
60+
export WAV2LIP_PORT=7860
61+
export ANIMATION_PORT=9066
62+
export INFERENCE_MODE='wav2lip+gfpgan'
63+
export CHECKPOINT_PATH='/usr/local/lib/python3.10/dist-packages/Wav2Lip/checkpoints/wav2lip_gan.pth'
64+
export FACE="comps/animation/wav2lip/assets/img/avatar1.jpg"
65+
# export AUDIO='assets/audio/eg3_ref.wav' # audio file path is optional, will use base64str in the post request as input if is 'None'
66+
export AUDIO='None'
67+
export FACESIZE=96
68+
export OUTFILE="comps/animation/wav2lip/assets/outputs/result.mp4"
69+
export GFPGAN_MODEL_VERSION=1.4 # latest version, can roll back to v1.3 if needed
70+
export UPSCALE_FACTOR=1
71+
export FPS=10
72+
```
73+
74+
# 🚀2. Run the Docker container
75+
76+
## 2.1 Run Wav2Lip Microservice
77+
78+
- Xeon CPU
79+
80+
```bash
81+
docker run --privileged -d --name "wav2lip-service" -p 7860:7860 --ipc=host -w /home/user/comps/animation/wav2lip -e PYTHON=/usr/bin/python3.11 -e DEVICE=$DEVICE -e INFERENCE_MODE=$INFERENCE_MODE -e CHECKPOINT_PATH=$CHECKPOINT_PATH -e FACE=$FACE -e AUDIO=$AUDIO -e FACESIZE=$FACESIZE -e OUTFILE=$OUTFILE -e GFPGAN_MODEL_VERSION=$GFPGAN_MODEL_VERSION -e UPSCALE_FACTOR=$UPSCALE_FACTOR -e FPS=$FPS -e WAV2LIP_PORT=$WAV2LIP_PORT opea/wav2lip:latest
82+
```
83+
84+
- Gaudi2 HPU
85+
86+
```bash
87+
docker run --privileged -d --name "wav2lip-gaudi-service" -p 7860:7860 --runtime=habana --cap-add=sys_nice --net=host --ipc=host -w /home/user/comps/animation/wav2lip -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none -e PYTHON=/usr/bin/python3.10 -e DEVICE=$DEVICE -e INFERENCE_MODE=$INFERENCE_MODE -e CHECKPOINT_PATH=$CHECKPOINT_PATH -e FACE=$FACE -e AUDIO=$AUDIO -e FACESIZE=$FACESIZE -e OUTFILE=$OUTFILE -e GFPGAN_MODEL_VERSION=$GFPGAN_MODEL_VERSION -e UPSCALE_FACTOR=$UPSCALE_FACTOR -e FPS=$FPS -e WAV2LIP_PORT=$WAV2LIP_PORT opea/wav2lip-gaudi:latest
88+
```
89+
90+
## 2.2 Run Animation Microservice
91+
92+
```bash
93+
docker run -d -p 9066:9066 --ipc=host --name "animation-service" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e WAV2LIP_ENDPOINT=http://$ip_address:7860 opea/animation:latest
94+
```
95+
96+
# 🚀3. Validate Microservice
97+
98+
Once microservice starts, user can use below script to validate the running microservice.
99+
100+
## 3.1 Validate Wav2Lip service
101+
102+
```bash
103+
cd GenAIComps/comps/animation/wav2lip
104+
python3 dependency/check_wav2lip_server.py
105+
```
106+
107+
## 3.2 Validate Animation service
108+
109+
```bash
110+
cd GenAIComps
111+
export ip_address=$(hostname -I | awk '{print $1}')
112+
curl http://${ip_address}:9066/v1/animation -X POST -H "Content-Type: application/json" -d @comps/animation/wav2lip/assets/audio/sample_question.json
113+
```
114+
115+
or
116+
117+
```bash
118+
cd GenAIComps/comps/animation/wav2lip
119+
python3 check_animation_server.py
120+
```
121+
122+
The expected output is a message similar to the following:
123+
124+
```bash
125+
{'wav2lip_result': '.../GenAIComps/comps/animation/wav2lip/assets/outputs/result.mp4'}
126+
```
127+
128+
Please find "comps/animation/wav2lip/assets/outputs/result.mp4" as a reference generated video.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Copyright (c) 2013--2023, librosa development team.
4+
# Copyright 1999-2003 The OpenLDAP Foundation, Redwood City, California, USA. All Rights Reserved.
5+
# Copyright (c) 2012, Anaconda, Inc. All rights reserved.
6+
7+
import json
8+
import os
9+
import time
10+
11+
import requests
12+
13+
# GenAIComps
14+
from comps import CustomLogger
15+
16+
logger = CustomLogger("animation")
17+
logflag = os.getenv("LOGFLAG", False)
18+
from comps import (
19+
Base64ByteStrDoc,
20+
ServiceType,
21+
VideoPath,
22+
opea_microservices,
23+
register_microservice,
24+
register_statistics,
25+
statistics_dict,
26+
)
27+
28+
29+
# Register the microservice
30+
@register_microservice(
31+
name="opea_service@animation",
32+
service_type=ServiceType.ANIMATION,
33+
endpoint="/v1/animation",
34+
host="0.0.0.0",
35+
port=9066,
36+
input_datatype=Base64ByteStrDoc,
37+
output_datatype=VideoPath,
38+
)
39+
@register_statistics(names=["opea_service@animation"])
40+
async def animate(audio: Base64ByteStrDoc):
41+
start = time.time()
42+
43+
byte_str = audio.byte_str
44+
inputs = {"audio": byte_str}
45+
if logflag:
46+
logger.info(inputs)
47+
48+
response = requests.post(url=f"{wav2lip_endpoint}/v1/wav2lip", data=json.dumps(inputs), proxies={"http": None})
49+
50+
outfile = response.json()["wav2lip_result"]
51+
if logflag:
52+
logger.info(response)
53+
logger.info(f"Video generated successfully, check {outfile} for the result.")
54+
55+
statistics_dict["opea_service@animation"].append_latency(time.time() - start, None)
56+
return VideoPath(video_path=outfile)
57+
58+
59+
if __name__ == "__main__":
60+
wav2lip_endpoint = os.getenv("WAV2LIP_ENDPOINT", "http://localhost:7860")
61+
logger.info("[animation - router] Animation initialized.")
62+
opea_microservices["opea_service@animation"].start()
1.21 MB
Binary file not shown.

comps/animation/wav2lip/assets/audio/sample_question.json

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.
148 KB
Loading
158 KB
Loading
2.52 MB
Loading

0 commit comments

Comments
 (0)