Spaces:
Sleeping
Sleeping
Commit
Β·
026f6aa
1
Parent(s):
11f5aeb
musicgen why not
Browse files
app.py
CHANGED
|
@@ -380,7 +380,42 @@ def transform_with_melodyflow_api(audio_path, prompt, solver="euler", flowstep=0
|
|
| 380 |
except Exception as e:
|
| 381 |
return None, f"β MelodyFlow API error: {str(e)}"
|
| 382 |
|
| 383 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
"""Calculate optimal bar count for given BPM to fit in ~10s"""
|
| 385 |
seconds_per_beat = 60.0 / bpm
|
| 386 |
seconds_per_bar = seconds_per_beat * 4
|
|
@@ -591,6 +626,41 @@ with gr.Blocks(title="stable-melodyflow") as iface:
|
|
| 591 |
transformed_audio = gr.Audio(label="transformed audio", type="filepath")
|
| 592 |
transform_status = gr.Textbox(label="status", value="Combine audio first")
|
| 593 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 594 |
# ========== EVENT HANDLERS ==========
|
| 595 |
|
| 596 |
# Update transform prompt when variation is selected
|
|
@@ -627,6 +697,13 @@ with gr.Blocks(title="stable-melodyflow") as iface:
|
|
| 627 |
inputs=[combined_audio, transform_prompt, transform_solver, transform_flowstep],
|
| 628 |
outputs=[transformed_audio, transform_status]
|
| 629 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 630 |
|
| 631 |
if __name__ == "__main__":
|
| 632 |
iface.launch()
|
|
|
|
| 380 |
except Exception as e:
|
| 381 |
return None, f"β MelodyFlow API error: {str(e)}"
|
| 382 |
|
| 383 |
+
def extend_with_musicgen_api(audio_path, prompt_duration, musicgen_model, output_duration):
|
| 384 |
+
"""Extend audio using the micro-slot-machine space API"""
|
| 385 |
+
if audio_path is None:
|
| 386 |
+
return None, "β No audio file provided"
|
| 387 |
+
|
| 388 |
+
try:
|
| 389 |
+
# Initialize client for micro-slot-machine space
|
| 390 |
+
client = Client("thepatch/micro-slot-machine")
|
| 391 |
+
|
| 392 |
+
print(f"πΌ MusicGen extension:")
|
| 393 |
+
print(f" Prompt duration: {prompt_duration}s")
|
| 394 |
+
print(f" Model: {musicgen_model}")
|
| 395 |
+
print(f" Output duration: {output_duration}s")
|
| 396 |
+
|
| 397 |
+
# Call the continue_music API
|
| 398 |
+
result = client.predict(
|
| 399 |
+
input_audio_path=handle_file(audio_path),
|
| 400 |
+
prompt_duration=str(prompt_duration),
|
| 401 |
+
musicgen_model=musicgen_model,
|
| 402 |
+
output_duration=output_duration,
|
| 403 |
+
api_name="/continue_music"
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
if result:
|
| 407 |
+
# Save the result locally
|
| 408 |
+
output_filename = f"musicgen_extended_{random.randint(1000, 9999)}.wav"
|
| 409 |
+
import shutil
|
| 410 |
+
shutil.copy2(result, output_filename)
|
| 411 |
+
|
| 412 |
+
status_msg = f"β
Extended with {musicgen_model} (prompt: {prompt_duration}s, output: {output_duration}s)"
|
| 413 |
+
return output_filename, status_msg
|
| 414 |
+
else:
|
| 415 |
+
return None, "β MusicGen API returned no results"
|
| 416 |
+
|
| 417 |
+
except Exception as e:
|
| 418 |
+
return None, f"β MusicGen API error: {str(e)}"
|
| 419 |
"""Calculate optimal bar count for given BPM to fit in ~10s"""
|
| 420 |
seconds_per_beat = 60.0 / bpm
|
| 421 |
seconds_per_bar = seconds_per_beat * 4
|
|
|
|
| 626 |
transformed_audio = gr.Audio(label="transformed audio", type="filepath")
|
| 627 |
transform_status = gr.Textbox(label="status", value="Combine audio first")
|
| 628 |
|
| 629 |
+
# ========== MUSICGEN EXTENSION ==========
|
| 630 |
+
gr.Markdown("## step four (optional): extend with musicgen")
|
| 631 |
+
|
| 632 |
+
with gr.Row():
|
| 633 |
+
with gr.Column():
|
| 634 |
+
musicgen_prompt_duration = gr.Dropdown(
|
| 635 |
+
label="prompt duration (seconds)",
|
| 636 |
+
choices=[3, 5, 7, 10],
|
| 637 |
+
value=5,
|
| 638 |
+
info="how much of the end to use as prompt for continuation"
|
| 639 |
+
)
|
| 640 |
+
musicgen_output_duration = gr.Slider(
|
| 641 |
+
label="extension duration (seconds)",
|
| 642 |
+
minimum=10,
|
| 643 |
+
maximum=30,
|
| 644 |
+
step=1,
|
| 645 |
+
value=20,
|
| 646 |
+
info="how much new audio to generate"
|
| 647 |
+
)
|
| 648 |
+
|
| 649 |
+
with gr.Column():
|
| 650 |
+
musicgen_model_choice = gr.Dropdown(
|
| 651 |
+
label="musicgen model",
|
| 652 |
+
choices=[
|
| 653 |
+
"thepatch/vanya_ai_dnb_0.1 (small)",
|
| 654 |
+
"thepatch/bleeps-medium (medium)"
|
| 655 |
+
],
|
| 656 |
+
value="thepatch/vanya_ai_dnb_0.1 (small)",
|
| 657 |
+
info="drum & bass focused vs experimental bleeps"
|
| 658 |
+
)
|
| 659 |
+
|
| 660 |
+
extend_btn = gr.Button("extend with musicgen", variant="primary", size="lg")
|
| 661 |
+
extended_audio = gr.Audio(label="extended audio", type="filepath")
|
| 662 |
+
extend_status = gr.Textbox(label="status", value="Transform audio first")
|
| 663 |
+
|
| 664 |
# ========== EVENT HANDLERS ==========
|
| 665 |
|
| 666 |
# Update transform prompt when variation is selected
|
|
|
|
| 697 |
inputs=[combined_audio, transform_prompt, transform_solver, transform_flowstep],
|
| 698 |
outputs=[transformed_audio, transform_status]
|
| 699 |
)
|
| 700 |
+
|
| 701 |
+
# Extend with MusicGen
|
| 702 |
+
extend_btn.click(
|
| 703 |
+
extend_with_musicgen_api,
|
| 704 |
+
inputs=[transformed_audio, musicgen_prompt_duration, musicgen_model_choice, musicgen_output_duration],
|
| 705 |
+
outputs=[extended_audio, extend_status]
|
| 706 |
+
)
|
| 707 |
|
| 708 |
if __name__ == "__main__":
|
| 709 |
iface.launch()
|