Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import os
|
|
7 |
import uuid
|
8 |
import shutil
|
9 |
import gzip
|
|
|
10 |
|
11 |
# Importing the model-related functions
|
12 |
from stable_audio_tools import get_pretrained_model
|
@@ -81,19 +82,28 @@ def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
|
81 |
output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
|
82 |
print("Audio normalized and converted.")
|
83 |
|
84 |
-
# Generate a unique filename for the output
|
85 |
-
unique_filename = f"output_{uuid.uuid4().hex}.wav"
|
86 |
-
print(f"Saving audio to file: {unique_filename}")
|
87 |
|
88 |
-
# Save to file
|
89 |
-
torchaudio.save(unique_filename, output, sample_rate)
|
90 |
-
print(f"Audio saved: {unique_filename}")
|
91 |
|
92 |
-
compressed_filename = compress_file(unique_filename)
|
93 |
-
return compressed_filename
|
94 |
|
95 |
# # Return the path to the generated audio file
|
96 |
# return unique_filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
99 |
DESCRIPTION = "Welcome to Raptor APIs"
|
|
|
7 |
import uuid
|
8 |
import shutil
|
9 |
import gzip
|
10 |
+
import io
|
11 |
|
12 |
# Importing the model-related functions
|
13 |
from stable_audio_tools import get_pretrained_model
|
|
|
82 |
output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
|
83 |
print("Audio normalized and converted.")
|
84 |
|
85 |
+
# # Generate a unique filename for the output
|
86 |
+
# unique_filename = f"output_{uuid.uuid4().hex}.wav"
|
87 |
+
# print(f"Saving audio to file: {unique_filename}")
|
88 |
|
89 |
+
# # Save to file
|
90 |
+
# torchaudio.save(unique_filename, output, sample_rate)
|
91 |
+
# print(f"Audio saved: {unique_filename}")
|
92 |
|
93 |
+
# compressed_filename = compress_file(unique_filename)
|
94 |
+
# return compressed_filename
|
95 |
|
96 |
# # Return the path to the generated audio file
|
97 |
# return unique_filename
|
98 |
+
|
99 |
+
# Convert audio tensor to bytes
|
100 |
+
byte_io = io.BytesIO()
|
101 |
+
torchaudio.save(byte_io, output, sample_rate, format="wav")
|
102 |
+
byte_io.seek(0)
|
103 |
+
audio_bytes = byte_io.read()
|
104 |
+
print("Audio converted to bytes.")
|
105 |
+
|
106 |
+
return audio_bytes
|
107 |
|
108 |
|
109 |
DESCRIPTION = "Welcome to Raptor APIs"
|