Commit
·
8455f94
1
Parent(s):
a0646fa
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,17 @@ from transformers import MusicgenForConditionalGeneration, MusicgenProcessor, se
|
|
9 |
from transformers.generation.streamers import BaseStreamer
|
10 |
|
11 |
import gradio as gr
|
12 |
-
import spaces
|
13 |
|
14 |
|
15 |
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
|
16 |
processor = MusicgenProcessor.from_pretrained("facebook/musicgen-small")
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
title = "MusicGen Streaming"
|
19 |
|
20 |
description = """
|
@@ -175,17 +180,10 @@ target_dtype = np.int16
|
|
175 |
max_range = np.iinfo(target_dtype).max
|
176 |
|
177 |
|
178 |
-
@spaces.GPU
|
179 |
def generate_audio(text_prompt, audio_length_in_s=10.0, play_steps_in_s=2.0, seed=0):
|
180 |
max_new_tokens = int(frame_rate * audio_length_in_s)
|
181 |
play_steps = int(frame_rate * play_steps_in_s)
|
182 |
|
183 |
-
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
184 |
-
if device != model.device:
|
185 |
-
model.to(device)
|
186 |
-
if device == "cuda:0":
|
187 |
-
model.half();
|
188 |
-
|
189 |
inputs = processor(
|
190 |
text=text_prompt,
|
191 |
padding=True,
|
|
|
9 |
from transformers.generation.streamers import BaseStreamer
|
10 |
|
11 |
import gradio as gr
|
|
|
12 |
|
13 |
|
14 |
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
|
15 |
processor = MusicgenProcessor.from_pretrained("facebook/musicgen-small")
|
16 |
|
17 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
18 |
+
if device != model.device:
|
19 |
+
model.to(device)
|
20 |
+
if device == "cuda:0":
|
21 |
+
model.half()
|
22 |
+
|
23 |
title = "MusicGen Streaming"
|
24 |
|
25 |
description = """
|
|
|
180 |
max_range = np.iinfo(target_dtype).max
|
181 |
|
182 |
|
|
|
183 |
def generate_audio(text_prompt, audio_length_in_s=10.0, play_steps_in_s=2.0, seed=0):
|
184 |
max_new_tokens = int(frame_rate * audio_length_in_s)
|
185 |
play_steps = int(frame_rate * play_steps_in_s)
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
inputs = processor(
|
188 |
text=text_prompt,
|
189 |
padding=True,
|