Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,9 +19,12 @@ def generate_music(prompt, duration):
|
|
| 19 |
# Prepare inputs
|
| 20 |
inputs = processor(text=[prompt], return_tensors="pt").to(device)
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
| 23 |
with torch.no_grad():
|
| 24 |
-
audio = model.generate(**inputs, do_sample=True, guidance_scale=3,
|
| 25 |
|
| 26 |
sr = model.config.audio_encoder.sampling_rate
|
| 27 |
audio_arr = audio[0, 0].cpu().numpy()
|
|
@@ -30,10 +33,10 @@ def generate_music(prompt, duration):
|
|
| 30 |
tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
| 31 |
wavfile.write(tmp.name, rate=sr, data=audio_arr)
|
| 32 |
|
| 33 |
-
return tmp.name, f"β
Generated {duration}s of audio!"
|
| 34 |
|
| 35 |
with gr.Blocks(title="MusicGen πΆ") as demo:
|
| 36 |
-
gr.Markdown("# π΅ MusicGen β Text-to-Music Generator (
|
| 37 |
with gr.Row():
|
| 38 |
prompt = gr.Textbox(label="πΌ Describe your music", placeholder="e.g. dreamy lo-fi with soft piano")
|
| 39 |
duration = gr.Slider(4, 40, value=15, step=1, label="Duration (seconds)")
|
|
|
|
| 19 |
# Prepare inputs
|
| 20 |
inputs = processor(text=[prompt], return_tensors="pt").to(device)
|
| 21 |
|
| 22 |
+
# Approximate duration scaling
|
| 23 |
+
approx_tokens = int(256 * (duration / 8))
|
| 24 |
+
approx_tokens = min(approx_tokens, 2048)
|
| 25 |
+
|
| 26 |
with torch.no_grad():
|
| 27 |
+
audio = model.generate(**inputs, do_sample=True, guidance_scale=3, max_new_tokens=approx_tokens)
|
| 28 |
|
| 29 |
sr = model.config.audio_encoder.sampling_rate
|
| 30 |
audio_arr = audio[0, 0].cpu().numpy()
|
|
|
|
| 33 |
tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
| 34 |
wavfile.write(tmp.name, rate=sr, data=audio_arr)
|
| 35 |
|
| 36 |
+
return tmp.name, f"β
Generated {duration}s (approx) of audio!"
|
| 37 |
|
| 38 |
with gr.Blocks(title="MusicGen πΆ") as demo:
|
| 39 |
+
gr.Markdown("# π΅ MusicGen β Text-to-Music Generator (Stable 40s Version)")
|
| 40 |
with gr.Row():
|
| 41 |
prompt = gr.Textbox(label="πΌ Describe your music", placeholder="e.g. dreamy lo-fi with soft piano")
|
| 42 |
duration = gr.Slider(4, 40, value=15, step=1, label="Duration (seconds)")
|