harp-dev commited on
Commit
efa47b9
·
verified ·
1 Parent(s): 2a8b981

Check shared assets before reserving the GPU, and reserve 90 s rather than 180.

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -126,10 +126,22 @@ def silent_wav(sample_rate, seconds=0.1):
126
  return write_wav(np.zeros(int(seconds * sample_rate), dtype=np.float32), sample_rate)
127
 
128
 
129
- @spaces.GPU(duration=180)
130
- @torch.inference_mode()
131
  def process_fn(mode_name, description, lyrics, ref_voice_path, extract_vocals, temperature):
132
  """Generate a song from a description and lyrics, optionally guided by a reference voice."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  model, processor = get_mode(mode_name)
134
 
135
  model_inputs = processor(
 
126
  return write_wav(np.zeros(int(seconds * sample_rate), dtype=np.float32), sample_rate)
127
 
128
 
 
 
129
  def process_fn(mode_name, description, lyrics, ref_voice_path, extract_vocals, temperature):
130
  """Generate a song from a description and lyrics, optionally guided by a reference voice."""
131
+ # Checked before the GPU is reserved, so a request that cannot run spends none of the
132
+ # caller's ZeroGPU allowance
133
+ if not xcodec_ready:
134
+ raise gr.Error("Still preparing shared assets, please wait a moment and try again.")
135
+ if xcodec_error:
136
+ raise gr.Error(f"Failed to prepare shared assets: {xcodec_error}")
137
+
138
+ return sing(mode_name, description, lyrics, ref_voice_path, extract_vocals, temperature)
139
+
140
+
141
+ # Measured at about 43 s, building the model included
142
+ @spaces.GPU(duration=90)
143
+ @torch.inference_mode()
144
+ def sing(mode_name, description, lyrics, ref_voice_path, extract_vocals, temperature):
145
  model, processor = get_mode(mode_name)
146
 
147
  model_inputs = processor(