Skip to content

Commit cfffb4c

Browse files
ctao456rbrugaroZePan110kevinintelpre-commit-ci[bot]
authored
Initiate "AvatarChatbot" (audio) example (#923)
Signed-off-by: Chun Tao <chun.tao@intel.com> Signed-off-by: rbrugaro <rita.brugarolas.brufau@intel.com> Signed-off-by: ZePan110 <ze.pan@intel.com> Signed-off-by: Louie Tsai <louie.tsai@intel.com> Signed-off-by: chen, suyue <suyue.chen@intel.com> Co-authored-by: rbrugaro <rita.brugarolas.brufau@intel.com> Co-authored-by: ZePan110 <ze.pan@intel.com> Co-authored-by: kevinintel <hanwen.chang@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Louie Tsai <louie.tsai@intel.com> Co-authored-by: chen, suyue <suyue.chen@intel.com>
1 parent 41955f6 commit cfffb4c

30 files changed

+1776
-0
lines changed

AvatarChatbot/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.safetensors
2+
*.bin
3+
*.model
4+
*.log
5+
docker_compose/intel/cpu/xeon/data
6+
docker_compose/intel/hpu/gaudi/data

AvatarChatbot/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
# Copyright (C) 2024 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
FROM python:3.11-slim
7+
8+
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
9+
libgl1-mesa-glx \
10+
libjemalloc-dev \
11+
vim \
12+
git
13+
14+
RUN useradd -m -s /bin/bash user && \
15+
mkdir -p /home/user && \
16+
chown -R user /home/user/
17+
18+
WORKDIR /home/user/
19+
RUN git clone https://github.com/opea-project/GenAIComps.git
20+
WORKDIR /home/user/GenAIComps
21+
22+
RUN pip install --no-cache-dir --upgrade pip && \
23+
pip install --no-cache-dir -r /home/user/GenAIComps/requirements.txt
24+
25+
COPY ./avatarchatbot.py /home/user/avatarchatbot.py
26+
27+
ENV PYTHONPATH=$PYTHONPATH:/home/user/GenAIComps
28+
29+
USER user
30+
31+
WORKDIR /home/user
32+
33+
ENTRYPOINT ["python", "avatarchatbot.py"]

AvatarChatbot/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# AvatarChatbot Application
2+
3+
The AvatarChatbot service can be effortlessly deployed on either Intel Gaudi2 or Intel XEON Scalable Processors.
4+
5+
## AI Avatar Workflow
6+
7+
The AI Avatar example is implemented using both megaservices and the component-level microservices defined in [GenAIComps](https://github.com/opea-project/GenAIComps). The flow chart below shows the information flow between different megaservices and microservices for this example.
8+
9+
```mermaid
10+
---
11+
config:
12+
flowchart:
13+
nodeSpacing: 100
14+
rankSpacing: 100
15+
curve: linear
16+
themeVariables:
17+
fontSize: 42px
18+
---
19+
flowchart LR
20+
classDef blue fill:#ADD8E6,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
21+
classDef thistle fill:#D8BFD8,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
22+
classDef orange fill:#FBAA60,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
23+
classDef orchid fill:#C26DBC,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
24+
classDef invisible fill:transparent,stroke:transparent;
25+
style AvatarChatbot-Megaservice stroke:#000000
26+
27+
subgraph AvatarChatbot-Megaservice["AvatarChatbot Megaservice"]
28+
direction LR
29+
ASR([ASR Microservice]):::blue
30+
LLM([LLM Microservice]):::blue
31+
TTS([TTS Microservice]):::blue
32+
animation([Animation Microservice]):::blue
33+
end
34+
subgraph UserInterface["User Interface"]
35+
direction LR
36+
invis1[ ]:::invisible
37+
USER1([User Audio Query]):::orchid
38+
USER2([User Image/Video Query]):::orchid
39+
UI([UI server<br>]):::orchid
40+
end
41+
GW([AvatarChatbot GateWay<br>]):::orange
42+
subgraph .
43+
direction LR
44+
X([OPEA Microservice]):::blue
45+
Y{{Open Source Service}}:::thistle
46+
Z([OPEA Gateway]):::orange
47+
Z1([UI]):::orchid
48+
end
49+
50+
WHISPER{{Whisper service}}:::thistle
51+
TGI{{LLM service}}:::thistle
52+
T5{{Speecht5 service}}:::thistle
53+
WAV2LIP{{Wav2Lip service}}:::thistle
54+
55+
%% Connections %%
56+
direction LR
57+
USER1 -->|1| UI
58+
UI -->|2| GW
59+
GW <==>|3| AvatarChatbot-Megaservice
60+
ASR ==>|4| LLM ==>|5| TTS ==>|6| animation
61+
62+
direction TB
63+
ASR <-.->|3'| WHISPER
64+
LLM <-.->|4'| TGI
65+
TTS <-.->|5'| T5
66+
animation <-.->|6'| WAV2LIP
67+
68+
USER2 -->|1| UI
69+
UI <-.->|6'| WAV2LIP
70+
```
71+
72+
## Deploy AvatarChatbot Service
73+
74+
The AvatarChatbot service can be deployed on either Intel Gaudi2 AI Accelerator or Intel Xeon Scalable Processor.
75+
76+
### Deploy AvatarChatbot on Gaudi
77+
78+
Refer to the [Gaudi Guide](./docker_compose/intel/hpu/gaudi/README.md) for instructions on deploying AvatarChatbot on Gaudi.
79+
80+
### Deploy AvatarChatbot on Xeon
81+
82+
Refer to the [Xeon Guide](./docker_compose/intel/cpu/xeon/README.md) for instructions on deploying AvatarChatbot on Xeon.
83+
84+
## Supported Models
85+
86+
### ASR
87+
88+
The default model is [openai/whisper-small](https://huggingface.co/openai/whisper-small). It also supports all models in the Whisper family, such as `openai/whisper-large-v3`, `openai/whisper-medium`, `openai/whisper-base`, `openai/whisper-tiny`, etc.
89+
90+
To replace the model, please edit the `compose.yaml` and add the `command` line to pass the name of the model you want to use:
91+
92+
```yaml
93+
services:
94+
whisper-service:
95+
...
96+
command: --model_name_or_path openai/whisper-tiny
97+
```
98+
99+
### TTS
100+
101+
The default model is [microsoft/SpeechT5](https://huggingface.co/microsoft/speecht5_tts). We currently do not support replacing the model. More models under the commercial license will be added in the future.
102+
103+
### Animation
104+
105+
The default model is [Rudrabha/Wav2Lip](https://github.com/Rudrabha/Wav2Lip) and [TencentARC/GFPGAN](https://github.com/TencentARC/GFPGAN). We currently do not support replacing the model. More models under the commercial license such as [OpenTalker/SadTalker](https://github.com/OpenTalker/SadTalker) will be added in the future.
1.21 MB
Binary file not shown.

AvatarChatbot/assets/audio/sample_minecraft.json

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

AvatarChatbot/assets/audio/sample_question.json

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

AvatarChatbot/assets/audio/sample_whoareyou.json

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

AvatarChatbot/assets/img/avatar1.jpg

148 KB
Loading

AvatarChatbot/assets/img/avatar2.jpg

158 KB
Loading

AvatarChatbot/assets/img/avatar3.png

2.52 MB
Loading

AvatarChatbot/assets/img/avatar4.png

992 KB
Loading

AvatarChatbot/assets/img/avatar5.png

1.67 MB
Loading

AvatarChatbot/assets/img/avatar6.png

1.56 MB
Loading

AvatarChatbot/assets/img/design.png

169 KB
Loading
121 KB
Loading

AvatarChatbot/assets/img/gaudi.png

47.3 KB
Loading
19.9 KB
Loading

AvatarChatbot/assets/img/opea_qr.png

24.8 KB
Loading

AvatarChatbot/assets/img/xeon.jpg

22.2 KB
Loading
Binary file not shown.
Binary file not shown.

AvatarChatbot/avatarchatbot.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import asyncio
5+
import os
6+
import sys
7+
8+
from comps import AvatarChatbotGateway, MicroService, ServiceOrchestrator, ServiceType
9+
10+
MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
11+
MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 8888))
12+
ASR_SERVICE_HOST_IP = os.getenv("ASR_SERVICE_HOST_IP", "0.0.0.0")
13+
ASR_SERVICE_PORT = int(os.getenv("ASR_SERVICE_PORT", 9099))
14+
LLM_SERVICE_HOST_IP = os.getenv("LLM_SERVICE_HOST_IP", "0.0.0.0")
15+
LLM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9000))
16+
TTS_SERVICE_HOST_IP = os.getenv("TTS_SERVICE_HOST_IP", "0.0.0.0")
17+
TTS_SERVICE_PORT = int(os.getenv("TTS_SERVICE_PORT", 9088))
18+
ANIMATION_SERVICE_HOST_IP = os.getenv("ANIMATION_SERVICE_HOST_IP", "0.0.0.0")
19+
ANIMATION_SERVICE_PORT = int(os.getenv("ANIMATION_SERVICE_PORT", 9066))
20+
21+
22+
def check_env_vars(env_var_list):
23+
for var in env_var_list:
24+
if os.getenv(var) is None:
25+
print(f"Error: The environment variable '{var}' is not set.")
26+
sys.exit(1) # Exit the program with a non-zero status code
27+
print("All environment variables are set.")
28+
29+
30+
class AvatarChatbotService:
31+
def __init__(self, host="0.0.0.0", port=8000):
32+
self.host = host
33+
self.port = port
34+
self.megaservice = ServiceOrchestrator()
35+
36+
def add_remote_service(self):
37+
asr = MicroService(
38+
name="asr",
39+
host=ASR_SERVICE_HOST_IP,
40+
port=ASR_SERVICE_PORT,
41+
endpoint="/v1/audio/transcriptions",
42+
use_remote_service=True,
43+
service_type=ServiceType.ASR,
44+
)
45+
llm = MicroService(
46+
name="llm",
47+
host=LLM_SERVICE_HOST_IP,
48+
port=LLM_SERVICE_PORT,
49+
endpoint="/v1/chat/completions",
50+
use_remote_service=True,
51+
service_type=ServiceType.LLM,
52+
)
53+
tts = MicroService(
54+
name="tts",
55+
host=TTS_SERVICE_HOST_IP,
56+
port=TTS_SERVICE_PORT,
57+
endpoint="/v1/audio/speech",
58+
use_remote_service=True,
59+
service_type=ServiceType.TTS,
60+
)
61+
animation = MicroService(
62+
name="animation",
63+
host=ANIMATION_SERVICE_HOST_IP,
64+
port=ANIMATION_SERVICE_PORT,
65+
endpoint="/v1/animation",
66+
use_remote_service=True,
67+
service_type=ServiceType.ANIMATION,
68+
)
69+
self.megaservice.add(asr).add(llm).add(tts).add(animation)
70+
self.megaservice.flow_to(asr, llm)
71+
self.megaservice.flow_to(llm, tts)
72+
self.megaservice.flow_to(tts, animation)
73+
self.gateway = AvatarChatbotGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
74+
75+
76+
if __name__ == "__main__":
77+
check_env_vars(
78+
[
79+
"MEGA_SERVICE_HOST_IP",
80+
"MEGA_SERVICE_PORT",
81+
"ASR_SERVICE_HOST_IP",
82+
"ASR_SERVICE_PORT",
83+
"LLM_SERVICE_HOST_IP",
84+
"LLM_SERVICE_PORT",
85+
"TTS_SERVICE_HOST_IP",
86+
"TTS_SERVICE_PORT",
87+
"ANIMATION_SERVICE_HOST_IP",
88+
"ANIMATION_SERVICE_PORT",
89+
]
90+
)
91+
92+
avatarchatbot = AvatarChatbotService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
93+
avatarchatbot.add_remote_service()

0 commit comments

Comments
 (0)