Spaces:
Running
on
L40S
Running
on
L40S
updated
Browse files
app.py
CHANGED
|
@@ -48,18 +48,31 @@ import os
|
|
| 48 |
# setup_flash_attention()
|
| 49 |
|
| 50 |
# Load model and processor
|
| 51 |
-
@gr.cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def load_model():
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
return
|
| 63 |
|
| 64 |
def generate_music(text_prompt, duration=10, temperature=1.0, top_k=250, top_p=0.0):
|
| 65 |
"""Generate music based on text prompt"""
|
|
@@ -83,7 +96,7 @@ def generate_music(text_prompt, duration=10, temperature=1.0, top_k=250, top_p=0
|
|
| 83 |
top_p=top_p,
|
| 84 |
cache_implementation="paged"
|
| 85 |
)
|
| 86 |
-
|
| 87 |
audio_data = audio_values[0, 0].cpu().numpy().astype(np.float32)
|
| 88 |
sample_rate = model.config.sample_rate
|
| 89 |
|
|
@@ -166,8 +179,6 @@ with gr.Blocks(title="MusicGen Large - Music Generation") as demo:
|
|
| 166 |
["classical violin concerto"],
|
| 167 |
["reggae with steel drums and bass"],
|
| 168 |
["rock ballad with electric guitar solo"],
|
| 169 |
-
["test example"],
|
| 170 |
-
|
| 171 |
],
|
| 172 |
inputs=text_input,
|
| 173 |
label="Example Prompts"
|
|
|
|
| 48 |
# setup_flash_attention()
|
| 49 |
|
| 50 |
# Load model and processor
|
| 51 |
+
# @gr.cache()
|
| 52 |
+
# def load_model():
|
| 53 |
+
# """Load the musicgen model and processor"""
|
| 54 |
+
# processor = AutoProcessor.from_pretrained("facebook/musicgen-large")
|
| 55 |
+
# model = MusicgenForConditionalGeneration.from_pretrained(
|
| 56 |
+
# "facebook/musicgen-large",
|
| 57 |
+
# torch_dtype=torch.float16,
|
| 58 |
+
# device="cuda",
|
| 59 |
+
# mode="S",
|
| 60 |
+
# __paged=True,
|
| 61 |
+
# )
|
| 62 |
+
# return processor, model
|
| 63 |
+
_processor, _model = None, None
|
| 64 |
+
|
| 65 |
def load_model():
|
| 66 |
+
global _processor, _model
|
| 67 |
+
if _model is None:
|
| 68 |
+
print("Initial model loading...")
|
| 69 |
+
_processor = AutoProcessor.from_pretrained("facebook/musicgen-large")
|
| 70 |
+
_model = MusicgenForConditionalGeneration.from_pretrained(
|
| 71 |
+
"facebook/musicgen-large",
|
| 72 |
+
torch_dtype=torch.float16,
|
| 73 |
+
device="cuda" if torch.cuda.is_available() else "cpu"
|
| 74 |
+
)
|
| 75 |
+
return _processor, _model
|
| 76 |
|
| 77 |
def generate_music(text_prompt, duration=10, temperature=1.0, top_k=250, top_p=0.0):
|
| 78 |
"""Generate music based on text prompt"""
|
|
|
|
| 96 |
top_p=top_p,
|
| 97 |
cache_implementation="paged"
|
| 98 |
)
|
| 99 |
+
|
| 100 |
audio_data = audio_values[0, 0].cpu().numpy().astype(np.float32)
|
| 101 |
sample_rate = model.config.sample_rate
|
| 102 |
|
|
|
|
| 179 |
["classical violin concerto"],
|
| 180 |
["reggae with steel drums and bass"],
|
| 181 |
["rock ballad with electric guitar solo"],
|
|
|
|
|
|
|
| 182 |
],
|
| 183 |
inputs=text_input,
|
| 184 |
label="Example Prompts"
|