Update app.py
Browse files
app.py
CHANGED
@@ -19,8 +19,8 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
19 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
20 |
|
21 |
# Load the StableAudio model from Hugging Face Hub
|
22 |
-
|
23 |
-
|
24 |
|
25 |
# Initialize Flask app
|
26 |
app = Flask(__name__)
|
@@ -39,8 +39,8 @@ def generate_audio():
|
|
39 |
try:
|
40 |
|
41 |
# Load the StableAudio model from Hugging Face Hub
|
42 |
-
pipe = StableAudioPipeline.from_pretrained("stabilityai/stable-audio-open-1.0", torch_dtype=torch_dtype)
|
43 |
-
pipe = pipe.to(device)
|
44 |
|
45 |
# Generate the audio using StableAudioPipeline
|
46 |
generator = torch.Generator(device)
|
@@ -61,7 +61,6 @@ def generate_audio():
|
|
61 |
output_io.truncate(0) # Clears any residual data from previous calls
|
62 |
output_audio = audio_output[0].T.float().cpu().numpy()
|
63 |
sf.write(output_io, output_audio, pipe.vae.sampling_rate, format="WAV") # Save as WAV or your preferred format
|
64 |
-
#output_io.truncate(0) # Clears the buffer's content
|
65 |
output_io.seek(0) # Reset buffer pointer to beginning
|
66 |
|
67 |
# Send the file in response as attachment for download
|
|
|
19 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
20 |
|
21 |
# Load the StableAudio model from Hugging Face Hub
|
22 |
+
pipe = StableAudioPipeline.from_pretrained("stabilityai/stable-audio-open-1.0", torch_dtype=torch_dtype)
|
23 |
+
pipe = pipe.to(device)
|
24 |
|
25 |
# Initialize Flask app
|
26 |
app = Flask(__name__)
|
|
|
39 |
try:
|
40 |
|
41 |
# Load the StableAudio model from Hugging Face Hub
|
42 |
+
#pipe = StableAudioPipeline.from_pretrained("stabilityai/stable-audio-open-1.0", torch_dtype=torch_dtype)
|
43 |
+
#pipe = pipe.to(device)
|
44 |
|
45 |
# Generate the audio using StableAudioPipeline
|
46 |
generator = torch.Generator(device)
|
|
|
61 |
output_io.truncate(0) # Clears any residual data from previous calls
|
62 |
output_audio = audio_output[0].T.float().cpu().numpy()
|
63 |
sf.write(output_io, output_audio, pipe.vae.sampling_rate, format="WAV") # Save as WAV or your preferred format
|
|
|
64 |
output_io.seek(0) # Reset buffer pointer to beginning
|
65 |
|
66 |
# Send the file in response as attachment for download
|