Bils commited on
Commit
77fd129
·
verified ·
1 Parent(s): 3b58485

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -50,7 +50,7 @@ def generate_script(user_prompt: str, model_id: str, token: str):
50
  # ---------------------------------------------------------------------
51
  # Load MusicGen Model (Encapsulated)
52
  # ---------------------------------------------------------------------
53
- @spaces.GPU(duration=300)
54
  @spaces.GPU(duration=300)
55
  def generate_audio(prompt: str, audio_length: int):
56
  try:
@@ -60,7 +60,7 @@ def generate_audio(prompt: str, audio_length: int):
60
  musicgen_model.to("cuda")
61
  inputs = musicgen_processor(text=[prompt], padding=True, return_tensors="pt")
62
  outputs = musicgen_model.generate(**inputs, max_new_tokens=audio_length)
63
- musicgen_model.to("cpu")
64
 
65
  sr = musicgen_model.config.audio_encoder.sampling_rate
66
  audio_data = outputs[0, 0].cpu().numpy()
@@ -74,7 +74,6 @@ def generate_audio(prompt: str, audio_length: int):
74
  return f"Error generating audio: {e}"
75
 
76
 
77
-
78
  # ---------------------------------------------------------------------
79
  # Gradio Interface Functions
80
  # ---------------------------------------------------------------------
 
50
  # ---------------------------------------------------------------------
51
  # Load MusicGen Model (Encapsulated)
52
  # ---------------------------------------------------------------------
53
+
54
  @spaces.GPU(duration=300)
55
  def generate_audio(prompt: str, audio_length: int):
56
  try:
 
60
  musicgen_model.to("cuda")
61
  inputs = musicgen_processor(text=[prompt], padding=True, return_tensors="pt")
62
  outputs = musicgen_model.generate(**inputs, max_new_tokens=audio_length)
63
+ musicgen_model.to("cpu") # Return the model to CPU
64
 
65
  sr = musicgen_model.config.audio_encoder.sampling_rate
66
  audio_data = outputs[0, 0].cpu().numpy()
 
74
  return f"Error generating audio: {e}"
75
 
76
 
 
77
  # ---------------------------------------------------------------------
78
  # Gradio Interface Functions
79
  # ---------------------------------------------------------------------