use list for JSON serialization
Browse files- __pycache__/handler.cpython-311.pyc +0 -0
- handler.py +1 -1
- output.wav +0 -0
- test.py +3 -1
- test_api.py +3 -12
__pycache__/handler.cpython-311.pyc
CHANGED
Binary files a/__pycache__/handler.cpython-311.pyc and b/__pycache__/handler.cpython-311.pyc differ
|
|
handler.py
CHANGED
@@ -32,7 +32,7 @@ class EndpointHandler():
|
|
32 |
|
33 |
# Create JSON response
|
34 |
response = {
|
35 |
-
"audio_data": audio_data,
|
36 |
"sampling_rate": sampling_rate
|
37 |
}
|
38 |
|
|
|
32 |
|
33 |
# Create JSON response
|
34 |
response = {
|
35 |
+
"audio_data": audio_data.tolist(),
|
36 |
"sampling_rate": sampling_rate
|
37 |
}
|
38 |
|
output.wav
CHANGED
Binary files a/output.wav and b/output.wav differ
|
|
test.py
CHANGED
@@ -13,7 +13,8 @@ payload = {"inputs": "Lowfi hiphop with deep bass"}
|
|
13 |
pred=my_handler(payload)
|
14 |
|
15 |
|
16 |
-
audio_data = pred["audio_data"]
|
|
|
17 |
sampling_rate = pred["sampling_rate"]
|
18 |
|
19 |
# Write the audio data to a WAV file
|
@@ -21,3 +22,4 @@ output_file_path = "output.wav" # Specify the file path
|
|
21 |
sf.write(output_file_path, audio_data, sampling_rate)
|
22 |
|
23 |
print("Audio file saved successfully.")
|
|
|
|
13 |
pred=my_handler(payload)
|
14 |
|
15 |
|
16 |
+
audio_data = np.array(pred["audio_data"], dtype=np.float32)
|
17 |
+
|
18 |
sampling_rate = pred["sampling_rate"]
|
19 |
|
20 |
# Write the audio data to a WAV file
|
|
|
22 |
sf.write(output_file_path, audio_data, sampling_rate)
|
23 |
|
24 |
print("Audio file saved successfully.")
|
25 |
+
|
test_api.py
CHANGED
@@ -3,7 +3,7 @@ import base64
|
|
3 |
import soundfile as sf
|
4 |
import numpy as np
|
5 |
|
6 |
-
API_URL = "https://
|
7 |
headers = {
|
8 |
"Accept" : "application/json",
|
9 |
"Authorization": "Bearer token",
|
@@ -21,20 +21,11 @@ response = query({
|
|
21 |
|
22 |
print(response)
|
23 |
|
24 |
-
|
25 |
-
audio_base64 = response["audio_base64"]
|
26 |
sampling_rate = response["sampling_rate"]
|
27 |
|
28 |
-
# Decode the base64-encoded audio data
|
29 |
-
audio_binary = base64.b64decode(audio_base64)
|
30 |
-
# Convert binary audio data to a NumPy array
|
31 |
-
audio_np = np.frombuffer(audio_binary, dtype=np.int16)
|
32 |
-
|
33 |
-
# Print the shape of the audio data
|
34 |
-
print("Shape of audio data:", audio_np.shape)
|
35 |
-
|
36 |
# Write the audio data to a WAV file
|
37 |
output_file_path = "output.wav" # Specify the file path
|
38 |
-
sf.write(output_file_path,
|
39 |
|
40 |
print("Audio file saved successfully.")
|
|
|
3 |
import soundfile as sf
|
4 |
import numpy as np
|
5 |
|
6 |
+
API_URL = "https://dcixo8iy1d0t2cq9.us-east-1.aws.endpoints.huggingface.cloud"
|
7 |
headers = {
|
8 |
"Accept" : "application/json",
|
9 |
"Authorization": "Bearer token",
|
|
|
21 |
|
22 |
print(response)
|
23 |
|
24 |
+
audio_data = response["audio_data"]
|
|
|
25 |
sampling_rate = response["sampling_rate"]
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Write the audio data to a WAV file
|
28 |
output_file_path = "output.wav" # Specify the file path
|
29 |
+
sf.write(output_file_path, audio_data, sampling_rate)
|
30 |
|
31 |
print("Audio file saved successfully.")
|