Skip to content

Commit bba8404

Browse files
committed
update the end of file char
Signed-off-by: Mustafa <[email protected]>
1 parent e8cd092 commit bba8404

File tree

11 files changed

+113
-34
lines changed

11 files changed

+113
-34
lines changed

.github/workflows/docker/compose/dataprep-compose-cd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ services:
4242
dataprep-audio2text:
4343
build:
4444
dockerfile: comps/dataprep/multimedia2text/video2audio/Dockerfile
45-
image: ${REGISTRY:-opea}/dataprep-audio2text:${TAG:-latest}
45+
image: ${REGISTRY:-opea}/dataprep-audio2text:${TAG:-latest}

comps/dataprep/multimedia2text/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ python comps/dataprep/multimedia2text/audio2text/check_a2t_server.py
127127
Expected output:
128128

129129
```
130-
{'downstream_black_list': [], 'id': '21b0459477abea6d85d20f4b5ddcb714', 'query': 'who is pat gelsinger'}
130+
Test passed successfully!
131131
```
132132

133133
*Note: The `id` value will be different.*
@@ -217,8 +217,4 @@ To stop and remove the Docker containers and images associated with the multimed
217217

218218
```bash
219219
docker image prune -a
220-
```
221-
222-
223-
224-
220+
```

comps/dataprep/multimedia2text/audio2text/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ ENV PYTHONPATH=$PYTHONPATH:/home/user
3434
WORKDIR /home/user/comps/dataprep/multimedia2text/audio2text
3535

3636
# Define the entry point for the container
37-
ENTRYPOINT ["python", "audio2text.py"]
37+
ENTRYPOINT ["python", "audio2text.py"]

comps/dataprep/multimedia2text/audio2text/audio2text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ async def audio_to_text(audio: Base64ByteStrDoc):
8585

8686
except Exception as e:
8787
logger.error(f"Failed to start the microservice: {e}")
88-
raise
88+
raise

comps/dataprep/multimedia2text/audio2text/check_a2t_server.py

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,81 @@
55
import json
66
import os
77
import requests
8-
import uuid
9-
import urllib.request
8+
import argparse
109

10+
# Get the root folder of the current script
11+
root_folder = os.path.dirname(os.path.abspath(__file__))
1112

12-
uid = str(uuid.uuid4())
13-
file_name = uid + ".wav"
13+
def audio_to_text(path_to_audio):
14+
"""
15+
Convert an audio file to text by sending a request to the server.
16+
17+
Args:
18+
path_to_audio (str): Path to the audio file.
19+
20+
Returns:
21+
str: The transcribed text.
22+
"""
23+
file_name = os.path.join(root_folder, path_to_audio)
1424

15-
urllib.request.urlretrieve(
16-
"https://github.com/intel/intel-extension-for-transformers/raw/main/intel_extension_for_transformers/neural_chat/assets/audio/sample.wav",
17-
file_name,
18-
)
25+
# Read the audio file and encode it in base64
26+
with open(file_name, "rb") as f:
27+
audio_base64_str = base64.b64encode(f.read()).decode("utf-8")
28+
29+
endpoint = "http://localhost:9099/v1/audio/transcriptions"
30+
inputs = {"byte_str": audio_base64_str}
31+
32+
# Send the POST request to the server
33+
response = requests.post(url=endpoint, data=json.dumps(inputs), proxies={"http": None})
34+
35+
# Check if the request was successful
36+
response.raise_for_status()
37+
38+
# Return the transcribed text
39+
return response.json()['query']
1940

20-
# Read and encode the audio file in base64
21-
with open(file_name, "rb") as f:
22-
test_audio_base64_str = base64.b64encode(f.read()).decode("utf-8")
23-
os.remove(file_name)
41+
def check_response(response):
42+
"""
43+
Check the response from the server and print the result.
44+
45+
Args:
46+
response (str): The transcribed text from the server.
47+
"""
48+
expected_response = "well"
49+
assert response == expected_response, f"Expected '{expected_response}', but got '{response}'"
50+
print("Test passed successfully!")
2451

25-
# Define the endpoint and the input data
26-
endpoint = "http://localhost:9099/v1/audio/transcriptions"
27-
inputs = {"byte_str": test_audio_base64_str}
52+
def read_config():
53+
"""
54+
Read the configuration parameters from the input file.
55+
56+
Returns:
57+
argparse.Namespace: Parsed arguments.
58+
"""
59+
# Create an argument parser
60+
parser = argparse.ArgumentParser(description="Process configuration parameters.")
61+
62+
# Add argument for the audio file path
63+
parser.add_argument(
64+
"--path_to_audio",
65+
help="Location of the audio file that will be converted to text.",
66+
required=False,
67+
default=os.path.join(root_folder, "../data/intel_short.wav")
68+
)
69+
70+
# Parse the arguments
71+
args = parser.parse_args()
72+
73+
# Return the parsed arguments
74+
return args
2875

29-
# Send the POST request to the endpoint
30-
response = requests.post(url=endpoint, data=json.dumps(inputs), proxies={"http": None})
31-
32-
# Print the response from the server
33-
print(response.json())
76+
if __name__ == "__main__":
77+
# Read the configuration parameters
78+
args = read_config()
79+
80+
# Convert audio to text
81+
response = audio_to_text(args.path_to_audio)
82+
83+
# Check the response
84+
check_response(response)
85+

comps/dataprep/multimedia2text/check_multimedia2text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ def test_multimedia2text_data():
142142
test_multimedia2text_data()
143143

144144
except AssertionError as e:
145-
print(f"Test failed: {e}")
145+
print(f"Test failed: {e}")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Test Data for Document Summarization
2+
3+
## Overview
4+
5+
This document provides information about the test data used for the Document Summarization application.
6+
7+
## Source of Test Data
8+
9+
The data used for testing originated from the following video:
10+
11+
[YouTube Video](https://www.youtube.com/watch?v=HUpnCtJRTg4)
12+
13+
## Description of Test Data
14+
15+
1. **Video File**: We extracted a 1-second segment from the above video and saved it as `intel_short.mp4`.
16+
2. **Audio File**: The audio was extracted from the `intel_short.mp4` video file and saved as `intel_short.wav`.
17+
18+
These files are used to test the functionality of the Document Summarization application, including the conversion of multimedia content to text.
19+
20+
## Files
21+
22+
- `intel_short.mp4`: A 1-second video segment extracted from the YouTube video.
23+
- `intel_short.wav`: An audio file converted from the `intel_short.mp4` video file.
24+
25+
## Usage
26+
27+
These files can be used to validate the multimedia-to-text services provided by the Document Summarization application. Ensure that the files are placed in the appropriate directory as specified in the application's configuration.
28+
29+
## License
30+
31+
The original video content is subject to the terms and conditions of YouTube and the content creator. The extracted segments are used solely for testing and validation purposes.

comps/dataprep/multimedia2text/multimedia2text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ async def audio_to_text(input: DocSumDoc):
9393

9494
except Exception as e:
9595
logger.error(f"Failed to start the multimedia2text microservice: {e}")
96-
raise
96+
raise

comps/dataprep/multimedia2text/video2audio/check_v2a_microserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ def read_config():
8787

8888
print("========= Audio file saved as ======")
8989
print(args.path_to_audio)
90-
print("====================================")
90+
print("====================================")

comps/dataprep/multimedia2text/video2audio/video2audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ def convert_video_to_audio_base64(self, video_file_name):
8787
# Convert the audio file to a base64 encoded string
8888
base64_str = self.convert_base64(audio_file_name)
8989

90-
return base64_str
90+
return base64_str

comps/dataprep/multimedia2text/video2audio/video2audio_microservice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ async def audio_to_text(request: Base64ByteStrDoc):
8484

8585
except Exception as e:
8686
logger.error(f"Failed to start the microservice: {e}")
87-
raise
87+
raise

0 commit comments

Comments
 (0)