Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ import gradio as gr
|
|
5 |
import spaces
|
6 |
import os
|
7 |
import uuid
|
|
|
|
|
8 |
|
9 |
# Importing the model-related functions
|
10 |
from stable_audio_tools import get_pretrained_model
|
@@ -16,6 +18,14 @@ def load_model():
|
|
16 |
model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
|
17 |
print("Model loaded successfully.")
|
18 |
return model, model_config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Function to set up, generate, and process the audio
|
21 |
@spaces.GPU(duration=60) # Allocate GPU only when this function is called
|
@@ -77,10 +87,13 @@ def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
|
77 |
|
78 |
# Save to file
|
79 |
torchaudio.save(unique_filename, output, sample_rate)
|
80 |
-
print(f"Audio saved: {unique_filename}")
|
|
|
|
|
|
|
81 |
|
82 |
-
# Return the path to the generated audio file
|
83 |
-
return unique_filename
|
84 |
|
85 |
|
86 |
DESCRIPTION = "Welcome to Raptor APIs"
|
|
|
5 |
import spaces
|
6 |
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
|
|
|
18 |
model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
|
19 |
print("Model loaded successfully.")
|
20 |
return model, model_config
|
21 |
+
|
22 |
+
def compress_file(file_path):
|
23 |
+
compressed_file_path = file_path + '.gz'
|
24 |
+
with open(file_path, 'rb') as f_in:
|
25 |
+
with gzip.open(compressed_file_path, 'wb') as f_out:
|
26 |
+
shutil.copyfileobj(f_in, f_out)
|
27 |
+
return compressed_file_path
|
28 |
+
|
29 |
|
30 |
# Function to set up, generate, and process the audio
|
31 |
@spaces.GPU(duration=60) # Allocate GPU only when this function is called
|
|
|
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"
|