artificialguybr commited on
Commit
4c9245b
1 Parent(s): 9b4a54c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -10,6 +10,11 @@ import uuid
10
  from stable_audio_tools import get_pretrained_model
11
  from stable_audio_tools.inference.generation import generate_diffusion_cond
12
 
 
 
 
 
 
13
  # Function to set up, generate, and process the audio
14
  @spaces.GPU(duration=120) # Allocate GPU only when this function is called
15
  def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
@@ -17,9 +22,9 @@ def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
17
 
18
  # Fetch the Hugging Face token from the environment variable
19
  hf_token = os.getenv('HF_TOKEN')
20
-
21
- # Download and set up the model
22
- model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
23
  sample_rate = model_config["sample_rate"]
24
  sample_size = model_config["sample_size"]
25
 
@@ -73,5 +78,8 @@ interface = gr.Interface(
73
  description="Generate variable-length stereo audio at 44.1kHz from text prompts using Stable Audio Open 1.0."
74
  )
75
 
 
 
 
76
  # Launch the Interface
77
  interface.launch()
 
10
  from stable_audio_tools import get_pretrained_model
11
  from stable_audio_tools.inference.generation import generate_diffusion_cond
12
 
13
+ # Load the model outside of the GPU-decorated function
14
+ def load_model():
15
+ model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
16
+ return model, model_config
17
+
18
  # Function to set up, generate, and process the audio
19
  @spaces.GPU(duration=120) # Allocate GPU only when this function is called
20
  def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
 
22
 
23
  # Fetch the Hugging Face token from the environment variable
24
  hf_token = os.getenv('HF_TOKEN')
25
+
26
+ # Use pre-loaded model and configuration
27
+ model, model_config = load_model()
28
  sample_rate = model_config["sample_rate"]
29
  sample_size = model_config["sample_size"]
30
 
 
78
  description="Generate variable-length stereo audio at 44.1kHz from text prompts using Stable Audio Open 1.0."
79
  )
80
 
81
+ # Pre-load the model to avoid multiprocessing issues
82
+ model, model_config = load_model()
83
+
84
  # Launch the Interface
85
  interface.launch()