Skip to content

Commit a19c222

Browse files
Refactor asr/tts components (opea-project#1083)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1040875 commit a19c222

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+759
-268
lines changed

.github/workflows/docker/compose/asr-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
services:
66
asr:
77
build:
8-
dockerfile: comps/asr/whisper/Dockerfile
8+
dockerfile: comps/asr/src/Dockerfile
99
image: ${REGISTRY:-opea}/asr:${TAG:-latest}
1010
whisper:
1111
build:
12-
dockerfile: comps/asr/whisper/dependency/Dockerfile
12+
dockerfile: comps/asr/src/integrations/dependency/whisper/Dockerfile
1313
image: ${REGISTRY:-opea}/whisper:${TAG:-latest}
1414
whisper-gaudi:
1515
build:
16-
dockerfile: comps/asr/whisper/dependency/Dockerfile.intel_hpu
16+
dockerfile: comps/asr/src/integrations/dependency/whisper/Dockerfile.intel_hpu
1717
image: ${REGISTRY:-opea}/whisper-gaudi:${TAG:-latest}

.github/workflows/docker/compose/tts-compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
services:
66
tts:
77
build:
8-
dockerfile: comps/tts/speecht5/Dockerfile
8+
dockerfile: comps/tts/src/Dockerfile
99
image: ${REGISTRY:-opea}/tts:${TAG:-latest}
1010
speecht5:
1111
build:
12-
dockerfile: comps/tts/speecht5/dependency/Dockerfile
12+
dockerfile: comps/tts/src/integrations/dependency/speecht5/Dockerfile
1313
image: ${REGISTRY:-opea}/speecht5:${TAG:-latest}
1414
speecht5-gaudi:
1515
build:
16-
dockerfile: comps/tts/speecht5/dependency/Dockerfile.intel_hpu
16+
dockerfile: comps/tts/src/integrations/dependency/speecht5/Dockerfile.intel_hpu
1717
image: ${REGISTRY:-opea}/speecht5-gaudi:${TAG:-latest}
1818
gpt-sovits:
1919
build:
20-
dockerfile: comps/tts/gpt-sovits/Dockerfile
20+
dockerfile: comps/tts/src/integrations/dependency/gpt-sovits/Dockerfile
2121
image: ${REGISTRY:-opea}/gpt-sovits:${TAG:-latest}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ The initially supported `Microservices` are described in the below table. More `
4343
| [Retriever](./comps/retrievers/README.md) | [LangChain](https://www.langchain.com)/[LlamaIndex](https://www.llamaindex.ai) | [BAAI/bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | [TEI](https://github.com/huggingface/text-embeddings-inference) | Xeon | Retriever on Xeon CPU |
4444
| [Reranking](./comps/reranks/tei/README.md) | [LangChain](https://www.langchain.com)/[LlamaIndex](https://www.llamaindex.ai) | [BAAI/bge-reranker-base](https://huggingface.co/BAAI/bge-reranker-base) | [TEI-Gaudi](https://github.com/huggingface/tei-gaudi) | Gaudi2 | Reranking on Gaudi2 |
4545
| [Reranking](./comps/reranks/tei/README.md) | [LangChain](https://www.langchain.com)/[LlamaIndex](https://www.llamaindex.ai) | [BBAAI/bge-reranker-base](https://huggingface.co/BAAI/bge-reranker-base) | [TEI](https://github.com/huggingface/text-embeddings-inference) | Xeon | Reranking on Xeon CPU |
46-
| [ASR](./comps/asr/whisper/README.md) | NA | [openai/whisper-small](https://huggingface.co/openai/whisper-small) | NA | Gaudi2 | Audio-Speech-Recognition on Gaudi2 |
47-
| [ASR](./comps/asr/whisper/README.md) | NA | [openai/whisper-small](https://huggingface.co/openai/whisper-small) | NA | Xeon | Audio-Speech-RecognitionS on Xeon CPU |
48-
| [TTS](./comps/tts/speecht5/README.md) | NA | [microsoft/speecht5_tts](https://huggingface.co/microsoft/speecht5_tts) | NA | Gaudi2 | Text-To-Speech on Gaudi2 |
49-
| [TTS](./comps/tts/speecht5/README.md) | NA | [microsoft/speecht5_tts](https://huggingface.co/microsoft/speecht5_tts) | NA | Xeon | Text-To-Speech on Xeon CPU |
46+
| [ASR](./comps/asr/src/README.md) | NA | [openai/whisper-small](https://huggingface.co/openai/whisper-small) | NA | Gaudi2 | Audio-Speech-Recognition on Gaudi2 |
47+
| [ASR](./comps/asr/src/README.md) | NA | [openai/whisper-small](https://huggingface.co/openai/whisper-small) | NA | Xeon | Audio-Speech-RecognitionS on Xeon CPU |
48+
| [TTS](./comps/tts/src/README.md) | NA | [microsoft/speecht5_tts](https://huggingface.co/microsoft/speecht5_tts) | NA | Gaudi2 | Text-To-Speech on Gaudi2 |
49+
| [TTS](./comps/tts/src/README.md) | NA | [microsoft/speecht5_tts](https://huggingface.co/microsoft/speecht5_tts) | NA | Xeon | Text-To-Speech on Xeon CPU |
5050
| [Dataprep](./comps/dataprep/README.md) | [Qdrant](https://qdrant.tech/) | [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) | NA | Gaudi2 | Dataprep on Gaudi2 |
5151
| [Dataprep](./comps/dataprep/README.md) | [Qdrant](https://qdrant.tech/) | [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) | NA | Xeon | Dataprep on Xeon CPU |
5252
| [Dataprep](./comps/dataprep/README.md) | [Redis](https://redis.io/) | [BAAI/bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | NA | Gaudi2 | Dataprep on Gaudi2 |
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
services:
5+
whisper-service:
6+
image: ${REGISTRY:-opea}/whisper:${TAG:-latest}
7+
container_name: whisper-service
8+
ports:
9+
- "7066:7066"
10+
ipc: host
11+
environment:
12+
no_proxy: ${no_proxy}
13+
http_proxy: ${http_proxy}
14+
https_proxy: ${https_proxy}
15+
restart: unless-stopped
16+
healthcheck:
17+
test: ["CMD", "curl", "-f", "http://localhost:7066/health"]
18+
interval: 10s
19+
timeout: 6s
20+
retries: 18
21+
asr:
22+
image: ${REGISTRY:-opea}/asr:${TAG:-latest}
23+
container_name: asr-service
24+
ports:
25+
- "9099:9099"
26+
ipc: host
27+
environment:
28+
ASR_ENDPOINT: ${ASR_ENDPOINT}
29+
dependes_on:
30+
speecht5-service:
31+
condition: service_healthy
32+
33+
networks:
34+
default:
35+
driver: bridge
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
services:
5+
whisper-service:
6+
image: ${REGISTRY:-opea}/whisper-gaudi:${TAG:-latest}
7+
container_name: whisper-service
8+
ports:
9+
- "7066:7066"
10+
ipc: host
11+
environment:
12+
no_proxy: ${no_proxy}
13+
http_proxy: ${http_proxy}
14+
https_proxy: ${https_proxy}
15+
HABANA_VISIBLE_DEVICES: all
16+
OMPI_MCA_btl_vader_single_copy_mechanism: none
17+
runtime: habana
18+
cap_add:
19+
- SYS_NICE
20+
restart: unless-stopped
21+
healthcheck:
22+
test: ["CMD", "curl", "-f", "http://localhost:7066/health"]
23+
interval: 10s
24+
timeout: 6s
25+
retries: 18
26+
asr:
27+
image: ${REGISTRY:-opea}/asr:${TAG:-latest}
28+
container_name: asr-service
29+
ports:
30+
- "3001:9099"
31+
ipc: host
32+
environment:
33+
ASR_ENDPOINT: ${ASR_ENDPOINT}
34+
dependes_on:
35+
speecht5-service:
36+
condition: service_healthy
37+
38+
networks:
39+
default:
40+
driver: bridge

comps/asr/whisper/Dockerfile renamed to comps/asr/src/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ COPY comps /home/user/comps
1616
RUN pip install --no-cache-dir --upgrade pip setuptools && \
1717
if [ "${ARCH}" = "cpu" ]; then \
1818
pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu ; \
19-
pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r /home/user/comps/asr/whisper/requirements.txt ; \
19+
pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r /home/user/comps/asr/src/requirements.txt ; \
2020
else \
21-
pip install --no-cache-dir -r /home/user/comps/asr/whisper/requirements.txt ; \
21+
pip install --no-cache-dir -r /home/user/comps/asr/src/requirements.txt ; \
2222
fi
2323

2424
ENV PYTHONPATH=$PYTHONPATH:/home/user
2525

26-
WORKDIR /home/user/comps/asr/whisper
26+
WORKDIR /home/user/comps/asr/src
2727

28-
ENTRYPOINT ["python", "asr.py"]
28+
ENTRYPOINT ["python", "opea_asr_microservice.py"]

comps/asr/whisper/README.md renamed to comps/asr/src/README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pip install -r requirements.txt
1717
- Xeon CPU
1818

1919
```bash
20-
cd dependency/
20+
cd integrations/dependency/whisper
2121
nohup python whisper_server.py --device=cpu &
2222
python check_whisper_server.py
2323
```
@@ -51,15 +51,15 @@ curl http://localhost:7066/v1/audio/transcriptions \
5151
### 1.3 Start ASR Service/Test
5252

5353
```bash
54-
cd ../
55-
python asr.py
54+
cd ../../..
55+
python opea_asr_microservice.py
5656
python check_asr_server.py
5757
```
5858

5959
While the Whisper service is running, you can start the ASR service. If the ASR service is running properly, you should see the output similar to the following:
6060

6161
```bash
62-
{'id': '0e686efd33175ce0ebcf7e0ed7431673', 'text': 'who is pat gelsinger'}
62+
{'text': 'who is pat gelsinger'}
6363
```
6464

6565
## 🚀2. Start Microservice with Docker (Option 2)
@@ -74,20 +74,20 @@ Alternatively, you can also start the ASR microservice with Docker.
7474

7575
```bash
7676
cd ../..
77-
docker build -t opea/whisper:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/asr/whisper/dependency/Dockerfile .
77+
docker build -t opea/whisper:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/asr/src/integrations/dependency/Dockerfile .
7878
```
7979

8080
- Gaudi2 HPU
8181

8282
```bash
8383
cd ../..
84-
docker build -t opea/whisper-gaudi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/asr/whisper/dependency/Dockerfile.intel_hpu .
84+
docker build -t opea/whisper-gaudi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/asr/src/integrations/dependency/Dockerfile.intel_hpu .
8585
```
8686

8787
#### 2.1.2 ASR Service Image
8888

8989
```bash
90-
docker build -t opea/asr:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/asr/whisper/Dockerfile .
90+
docker build -t opea/asr:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/asr/src/Dockerfile .
9191
```
9292

9393
### 2.2 Start Whisper and ASR Service
@@ -97,21 +97,21 @@ docker build -t opea/asr:latest --build-arg https_proxy=$https_proxy --build-arg
9797
- Xeon
9898

9999
```bash
100-
docker run -p 7066:7066 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy opea/whisper:latest
100+
docker run -p 7066:7066 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy opea/whisper:latest
101101
```
102102

103103
- Gaudi2 HPU
104104

105105
```bash
106-
docker run -p 7066:7066 --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy opea/whisper-gaudi:latest
106+
docker run -p 7066:7066 --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy opea/whisper-gaudi:latest
107107
```
108108

109109
#### 2.2.2 Start ASR service
110110

111111
```bash
112112
ip_address=$(hostname -I | awk '{print $1}')
113113

114-
docker run -d -p 9099:9099 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e ASR_ENDPOINT=http://$ip_address:7066 opea/asr:latest
114+
docker run -d -p 9099:9099 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e ASR_ENDPOINT=http://$ip_address:7066 opea/asr:latest
115115
```
116116

117117
#### 2.2.3 Test
@@ -120,8 +120,11 @@ docker run -d -p 9099:9099 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$
120120
# Use curl or python
121121

122122
# curl
123-
http_proxy="" curl http://localhost:9099/v1/audio/transcriptions -XPOST -d '{"byte_str": "UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"}' -H 'Content-Type: application/json'
124-
123+
wget https://github.com/intel/intel-extension-for-transformers/raw/main/intel_extension_for_transformers/neural_chat/assets/audio/sample.wav
124+
curl http://localhost:9099/v1/audio/transcriptions \
125+
-H "Content-Type: multipart/form-data" \
126+
-F file="@./sample.wav" \
127+
-F model="openai/whisper-small"
125128

126129
# python
127130
python check_asr_server.py

comps/asr/whisper/check_asr_server.py renamed to comps/asr/src/check_asr_server.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,24 @@
2020
file_name,
2121
)
2222

23-
with open(file_name, "rb") as f:
24-
test_audio_base64_str = base64.b64encode(f.read()).decode("utf-8")
25-
os.remove(file_name)
26-
2723
endpoint = "http://localhost:9099/v1/audio/transcriptions"
28-
inputs = {"byte_str": test_audio_base64_str}
29-
response = requests.post(url=endpoint, data=json.dumps(inputs), proxies={"http": None})
30-
print(response.json())
24+
headers = {"accept": "application/json"}
25+
26+
# Prepare the data and files
27+
data = {
28+
"model": "openai/whisper-small",
29+
"language": "english",
30+
}
31+
32+
try:
33+
with open(file_name, "rb") as audio_file:
34+
files = {"file": (file_name, audio_file)}
35+
response = requests.post(endpoint, headers=headers, data=data, files=files)
36+
if response.status_code != 200:
37+
print(f"Failure with {response.reason}!")
38+
else:
39+
print(response.json())
40+
except Exception as e:
41+
print(f"Failure with {e}!")
42+
43+
os.remove(file_name)

comps/asr/whisper/dependency/Dockerfile renamed to comps/asr/src/integrations/dependency/whisper/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ COPY --chown=user:user comps /home/user/comps
2020
USER user
2121

2222
RUN pip install --no-cache-dir --upgrade pip setuptools && \
23-
pip install --no-cache-dir -r /home/user/comps/asr/whisper/requirements.txt && \
23+
pip install --no-cache-dir -r /home/user/comps/asr/src/requirements.txt && \
2424
if [ "${ARCH}" = "cpu" ]; then \
2525
pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu ; \
26-
pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r /home/user/comps/asr/whisper/requirements.txt ; \
26+
pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r /home/user/comps/asr/src/requirements.txt ; \
2727
else \
28-
pip install --no-cache-dir -r /home/user/comps/asr/whisper/requirements.txt ; \
28+
pip install --no-cache-dir -r /home/user/comps/asr/src/requirements.txt ; \
2929
fi
3030

3131
ENV PYTHONPATH=$PYTHONPATH:/home/user
3232

33-
WORKDIR /home/user/comps/asr/whisper/dependency
33+
WORKDIR /home/user/comps/asr/src/integrations/dependency/whisper
3434

3535
ENTRYPOINT ["python", "whisper_server.py", "--device", "cpu"]

comps/asr/whisper/dependency/Dockerfile.intel_hpu renamed to comps/asr/src/integrations/dependency/whisper/Dockerfile.intel_hpu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ USER user
2323

2424
# Install requirements and optimum habana
2525
RUN pip install --no-cache-dir --upgrade pip && \
26-
pip install --no-cache-dir -r /home/user/comps/asr/whisper/requirements.txt && \
26+
pip install --no-cache-dir -r /home/user/comps/asr/src/requirements.txt && \
2727
pip install --no-cache-dir optimum[habana]
2828

2929
ENV PYTHONPATH=$PYTHONPATH:/home/users
3030

31-
WORKDIR /home/user/comps/asr/whisper/dependency
31+
WORKDIR /home/user/comps/asr/src/integrations/dependency/whisper
3232

3333
ENTRYPOINT ["python", "whisper_server.py", "--device", "hpu"]

0 commit comments

Comments
 (0)