Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initiate "AvatarChatbot" (audio) example #923

Merged
merged 87 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
694823a
updates needed for demo
ctao456 Oct 7, 2024
61d7003
Merge branch 'opea-project:main' into ctao/demo
ctao456 Oct 7, 2024
118ef6c
original pr content
ctao456 Oct 8, 2024
5043e0c
Revert "updates needed for demo"
ctao456 Oct 8, 2024
9c818e1
Update the mermaid flowchart for AvatarChatbot
ctao456 Oct 8, 2024
400dffb
update to follow latest opea format
ctao456 Oct 9, 2024
935f589
instruction finetune README improvement (#897)
rbrugaro Oct 8, 2024
1ebb159
Update docker image list. (#893)
ZePan110 Oct 8, 2024
70352cb
Update FaqGen README.md for its workflow (#910)
louie-tsai Oct 8, 2024
10ecc65
fix image name (#909)
chensuyue Oct 8, 2024
81f8177
Update AudioQnA README.md for its workflow (#903)
louie-tsai Oct 8, 2024
a712923
Update SearchQnA README.md for its workflow (#913)
louie-tsai Oct 8, 2024
a7ec55b
Optimize path and link validity check. (#866)
ZePan110 Oct 9, 2024
3b72607
update to format
ctao456 Oct 9, 2024
db19c2d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
6606811
remove debug imports
ctao456 Oct 9, 2024
13b43ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
b0514e8
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 9, 2024
248b7aa
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 14, 2024
7f63449
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 15, 2024
5bd776b
Update flowchart
ctao456 Oct 18, 2024
b62631f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2024
dca6e4f
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 18, 2024
a6d27c6
update compose.yaml
ctao456 Oct 18, 2024
71570fa
update flowchart
ctao456 Oct 18, 2024
03180ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2024
ec59fd4
Update structure
ctao456 Oct 19, 2024
1c1f45a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2024
caf32b9
Fix flowchart
ctao456 Oct 19, 2024
3d2e038
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2024
2a392f2
fix flowchart
ctao456 Oct 19, 2024
52c0854
update
ctao456 Oct 19, 2024
c846c30
update
ctao456 Oct 19, 2024
ccb8955
update
ctao456 Oct 19, 2024
cd0fb65
updates
ctao456 Oct 19, 2024
55e3286
update readme, videos on hpu
ctao456 Oct 19, 2024
12f3a32
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2024
b3cd787
updates, add support for xeon and gaudi
ctao456 Oct 19, 2024
0d77ff3
Merge branch 'ctao/opea' of https://github.com/ctao456/GenAIExamples …
ctao456 Oct 19, 2024
2125277
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2024
dd5c686
fix build.yaml
ctao456 Oct 19, 2024
0a76e96
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2024
2d5e789
update ui script
ctao456 Oct 19, 2024
a2ece43
Merge branch 'ctao/opea' of https://github.com/ctao456/GenAIExamples …
ctao456 Oct 19, 2024
dfc3927
comment subprocess lines
ctao456 Oct 19, 2024
4bf3cfc
fix syntax for hf api token env var
ctao456 Oct 19, 2024
8f01585
fix syntax in test scripts
ctao456 Oct 19, 2024
3810b0a
fix syntax in test script
ctao456 Oct 19, 2024
3b01d98
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 20, 2024
df6f976
use build.yaml to build images in test scripts; --no-cache flag added…
ctao456 Oct 21, 2024
9cf18d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 21, 2024
33fa94d
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 21, 2024
e6a54a3
update
ctao456 Oct 21, 2024
5533b0d
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 21, 2024
2be4759
add env vars in the beginning
ctao456 Oct 22, 2024
4db4ffd
update
ctao456 Oct 22, 2024
f81b578
add "IMAGE_REPO" in xeon test script
ctao456 Oct 22, 2024
0ca5532
update Docker container names
ctao456 Oct 22, 2024
2fa2fc4
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 22, 2024
a0bcf47
update test scripts
ctao456 Oct 22, 2024
33a3e37
update test scripts
ctao456 Oct 22, 2024
1b0a993
update test scripts
ctao456 Oct 22, 2024
ddae9ec
update test scripts
ctao456 Oct 22, 2024
8207732
update test scripts
ctao456 Oct 22, 2024
14a2916
update test scripts
ctao456 Oct 22, 2024
e3ce5c2
update test scripts
ctao456 Oct 22, 2024
029409d
update test script
ctao456 Oct 22, 2024
98e1c8a
Merge branch 'opea-project:main' into ctao/opea
ctao456 Oct 22, 2024
131ee6d
update on test scripts
ctao456 Oct 22, 2024
27795ae
Merge branch 'ctao/opea' of https://github.com/ctao456/GenAIExamples …
ctao456 Oct 22, 2024
f687755
update test scripts
ctao456 Oct 22, 2024
02be9e1
update
ctao456 Oct 22, 2024
fbbf1bd
update
ctao456 Oct 22, 2024
317dadc
update gaudi test
ctao456 Oct 22, 2024
83a1f75
udpate gaudi test
ctao456 Oct 22, 2024
3b24d19
update
ctao456 Oct 22, 2024
fd17782
update gaudi test
ctao456 Oct 22, 2024
53a57d0
update gaudi test
ctao456 Oct 22, 2024
9ab18be
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 22, 2024
dce2331
Merge branch 'ctao/opea' of https://github.com/ctao456/GenAIExamples …
ctao456 Oct 22, 2024
0f2b018
update gaudi test
ctao456 Oct 22, 2024
e1e7159
update gaudi test
ctao456 Oct 22, 2024
01f36f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 22, 2024
9851e4b
update
ctao456 Oct 22, 2024
c9b12cb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 22, 2024
6ad79b2
gaudi test script
ctao456 Oct 23, 2024
c08b0f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AvatarChatbot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.safetensors
*.bin
*.model
docker_compose/intel/cpu/xeon/data
docker_compose/intel/hpu/gaudi/data
33 changes: 33 additions & 0 deletions AvatarChatbot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

FROM python:3.11-slim

RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
libgl1-mesa-glx \
libjemalloc-dev \
vim \
git

RUN useradd -m -s /bin/bash user && \
mkdir -p /home/user && \
chown -R user /home/user/

WORKDIR /home/user/
RUN git clone https://github.com/opea-project/GenAIComps.git
WORKDIR /home/user/GenAIComps

RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r /home/user/GenAIComps/requirements.txt

COPY ./avatarchatbot.py /home/user/avatarchatbot.py

ENV PYTHONPATH=$PYTHONPATH:/home/user/GenAIComps

USER user

WORKDIR /home/user

ENTRYPOINT ["python", "avatarchatbot.py"]
105 changes: 105 additions & 0 deletions AvatarChatbot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# AvatarChatbot Application

The AvatarChatbot service can be effortlessly deployed on either Intel Gaudi2 or Intel XEON Scalable Processors.

## AI Avatar Workflow

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.

```mermaid
---
config:
flowchart:
nodeSpacing: 100
rankSpacing: 100
curve: linear
themeVariables:
fontSize: 42px
---
flowchart LR
classDef blue fill:#ADD8E6,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
classDef thistle fill:#D8BFD8,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
classDef orange fill:#FBAA60,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
classDef orchid fill:#C26DBC,stroke:#ADD8E6,stroke-width:2px,fill-opacity:0.5
classDef invisible fill:transparent,stroke:transparent;
style AvatarChatbot-Megaservice stroke:#000000

subgraph AvatarChatbot-Megaservice["AvatarChatbot Megaservice"]
direction LR
ASR([ASR Microservice]):::blue
LLM([LLM Microservice]):::blue
TTS([TTS Microservice]):::blue
animation([Animation Microservice]):::blue
end
subgraph UserInterface["User Interface"]
direction LR
invis1[ ]:::invisible
USER1([User Audio Query]):::orchid
USER2([User Image/Video Query]):::orchid
UI([UI server<br>]):::orchid
end
GW([AvatarChatbot GateWay<br>]):::orange
subgraph .
direction LR
X([OPEA Microservice]):::blue
Y{{Open Source Service}}:::thistle
Z([OPEA Gateway]):::orange
Z1([UI]):::orchid
end

WHISPER{{Whisper service}}:::thistle
TGI{{LLM service}}:::thistle
T5{{Speecht5 service}}:::thistle
WAV2LIP{{Wav2Lip service}}:::thistle

%% Connections %%
direction LR
USER1 -->|1| UI
UI -->|2| GW
GW <==>|3| AvatarChatbot-Megaservice
ASR ==>|4| LLM ==>|5| TTS ==>|6| animation

direction TB
ASR <-.->|3'| WHISPER
LLM <-.->|4'| TGI
TTS <-.->|5'| T5
animation <-.->|6'| WAV2LIP

USER2 -->|1| UI
UI <-.->|6'| WAV2LIP
```

## Deploy AvatarChatbot Service

The AvatarChatbot service can be deployed on either Intel Gaudi2 AI Accelerator or Intel Xeon Scalable Processor.

### Deploy AvatarChatbot on Gaudi

Refer to the [Gaudi Guide](./docker_compose/intel/hpu/gaudi/README.md) for instructions on deploying AvatarChatbot on Gaudi.

### Deploy AvatarChatbot on Xeon

Refer to the [Xeon Guide](./docker_compose/intel/cpu/xeon/README.md) for instructions on deploying AvatarChatbot on Xeon.

## Supported Models

### ASR

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.

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:

```yaml
services:
whisper-service:
...
command: --model_name_or_path openai/whisper-tiny
```

### TTS

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.

### Animation

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.
Binary file added AvatarChatbot/assets/audio/eg3_ref.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions AvatarChatbot/assets/audio/sample_minecraft.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions AvatarChatbot/assets/audio/sample_question.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions AvatarChatbot/assets/audio/sample_whoareyou.json

Large diffs are not rendered by default.

Binary file added AvatarChatbot/assets/img/avatar1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/avatar2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/avatar3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/avatar4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/avatar5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/avatar6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/flowchart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/gaudi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/opea_gh_qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/opea_qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AvatarChatbot/assets/img/xeon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
93 changes: 93 additions & 0 deletions AvatarChatbot/avatarchatbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import asyncio
import os
import sys

from comps import AvatarChatbotGateway, MicroService, ServiceOrchestrator, ServiceType

MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 8888))
ASR_SERVICE_HOST_IP = os.getenv("ASR_SERVICE_HOST_IP", "0.0.0.0")
ASR_SERVICE_PORT = int(os.getenv("ASR_SERVICE_PORT", 9099))
LLM_SERVICE_HOST_IP = os.getenv("LLM_SERVICE_HOST_IP", "0.0.0.0")
LLM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9000))
TTS_SERVICE_HOST_IP = os.getenv("TTS_SERVICE_HOST_IP", "0.0.0.0")
TTS_SERVICE_PORT = int(os.getenv("TTS_SERVICE_PORT", 9088))
ANIMATION_SERVICE_HOST_IP = os.getenv("ANIMATION_SERVICE_HOST_IP", "0.0.0.0")
ANIMATION_SERVICE_PORT = int(os.getenv("ANIMATION_SERVICE_PORT", 9066))


def check_env_vars(env_var_list):
for var in env_var_list:
if os.getenv(var) is None:
print(f"Error: The environment variable '{var}' is not set.")
sys.exit(1) # Exit the program with a non-zero status code
print("All environment variables are set.")


class AvatarChatbotService:
def __init__(self, host="0.0.0.0", port=8000):
self.host = host
self.port = port
self.megaservice = ServiceOrchestrator()

def add_remote_service(self):
asr = MicroService(
name="asr",
host=ASR_SERVICE_HOST_IP,
port=ASR_SERVICE_PORT,
endpoint="/v1/audio/transcriptions",
use_remote_service=True,
service_type=ServiceType.ASR,
)
llm = MicroService(
name="llm",
host=LLM_SERVICE_HOST_IP,
port=LLM_SERVICE_PORT,
endpoint="/v1/chat/completions",
use_remote_service=True,
service_type=ServiceType.LLM,
)
tts = MicroService(
name="tts",
host=TTS_SERVICE_HOST_IP,
port=TTS_SERVICE_PORT,
endpoint="/v1/audio/speech",
use_remote_service=True,
service_type=ServiceType.TTS,
)
animation = MicroService(
name="animation",
host=ANIMATION_SERVICE_HOST_IP,
port=ANIMATION_SERVICE_PORT,
endpoint="/v1/animation",
use_remote_service=True,
service_type=ServiceType.ANIMATION,
)
self.megaservice.add(asr).add(llm).add(tts).add(animation)
self.megaservice.flow_to(asr, llm)
self.megaservice.flow_to(llm, tts)
self.megaservice.flow_to(tts, animation)
self.gateway = AvatarChatbotGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)


if __name__ == "__main__":
check_env_vars(
[
"MEGA_SERVICE_HOST_IP",
"MEGA_SERVICE_PORT",
"ASR_SERVICE_HOST_IP",
"ASR_SERVICE_PORT",
"LLM_SERVICE_HOST_IP",
"LLM_SERVICE_PORT",
"TTS_SERVICE_HOST_IP",
"TTS_SERVICE_PORT",
"ANIMATION_SERVICE_HOST_IP",
"ANIMATION_SERVICE_PORT",
]
)

avatarchatbot = AvatarChatbotService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
avatarchatbot.add_remote_service()
Loading
Loading