Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
#==========================================================
|
| 2 |
# https://huggingface.co/spaces/asigalov61/Orpheus-Morpheus
|
| 3 |
-
#==========================================================
|
| 4 |
|
| 5 |
# -----------------------------
|
| 6 |
# CONFIGURATION & GLOBALS
|
|
@@ -522,6 +522,16 @@ def generate_music_and_state(input_midi,
|
|
| 522 |
|
| 523 |
return [final_composition] + outputs_flat
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
# -----------------------------
|
| 526 |
# GRADIO INTERFACE SETUP
|
| 527 |
# -----------------------------
|
|
@@ -571,24 +581,16 @@ with gr.Blocks() as orpheus_mosrpheus_app:
|
|
| 571 |
gr.Markdown("## Upload seed MIDI or click 'Generate' button for random output")
|
| 572 |
|
| 573 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
| 574 |
-
input_midi.upload(reset, [final_composition
|
| 575 |
-
[final_composition
|
| 576 |
|
| 577 |
gr.Markdown("## Generation options")
|
| 578 |
-
prime_instruments = gr.Dropdown(label="Prime instruments (select up to 5)", choices=list(Patch2number.keys()),
|
| 579 |
-
multiselect=True, max_choices=5, type="value",
|
| 580 |
-
info="NOTE: Custom MIDI overrides prime instruments"
|
| 581 |
-
)
|
| 582 |
-
|
| 583 |
-
prime_instruments.input(reset, [final_composition, generated_batches, block_lines],
|
| 584 |
-
[final_composition, generated_batches, block_lines])
|
| 585 |
|
| 586 |
-
num_prime_tokens = gr.Slider(
|
| 587 |
-
num_gen_tokens = gr.Slider(
|
| 588 |
requested_model = gr.Dropdown(label="Model to use",
|
| 589 |
choices=list(models_dict.keys()),
|
| 590 |
value=list(models_dict.keys())[0],
|
| 591 |
-
info="Use medium model when speed is important, use large models when quality is important"
|
| 592 |
)
|
| 593 |
model_temperature = gr.Slider(0.1, 1, value=0.9, step=0.01, label="Model temperature",
|
| 594 |
info="Increase for more creative output, decrease for more repetitive output"
|
|
@@ -596,13 +598,11 @@ with gr.Blocks() as orpheus_mosrpheus_app:
|
|
| 596 |
model_top_p = gr.Slider(0.1, 1.0, value=0.96, step=0.01, label="Model sampling top p value",
|
| 597 |
info="1 == Disabled"
|
| 598 |
)
|
| 599 |
-
add_drums = gr.Checkbox(value=False, label="Add drums")
|
| 600 |
-
add_outro = gr.Checkbox(value=False, label="Add an outro")
|
| 601 |
|
| 602 |
generate_btn = gr.Button("Generate", variant="primary")
|
| 603 |
|
| 604 |
gr.Markdown("## Batch Previews")
|
| 605 |
-
outputs = [final_composition
|
| 606 |
# Two outputs (audio and plot) for each batch
|
| 607 |
for i in range(NUM_OUT_BATCHES):
|
| 608 |
with gr.Tab(f"Batch # {i}"):
|
|
@@ -610,59 +610,25 @@ with gr.Blocks() as orpheus_mosrpheus_app:
|
|
| 610 |
plot_output = gr.Plot(label=f"Batch # {i} MIDI Plot")
|
| 611 |
midi_file = gr.File(label=f"Batch # {i} MIDI File")
|
| 612 |
outputs.extend([audio_output, plot_output, midi_file])
|
| 613 |
-
|
| 614 |
-
requested_model.change(
|
| 615 |
-
fn=update_state_from_dropdown,
|
| 616 |
-
inputs=[requested_model, model_selector],
|
| 617 |
-
outputs=model_selector
|
| 618 |
-
)
|
| 619 |
|
| 620 |
generate_btn.click(
|
| 621 |
generate_music_and_state,
|
| 622 |
[input_midi,
|
| 623 |
-
prime_instruments,
|
| 624 |
num_prime_tokens,
|
| 625 |
num_gen_tokens,
|
| 626 |
model_temperature,
|
| 627 |
model_top_p,
|
| 628 |
-
add_drums,
|
| 629 |
-
add_outro,
|
| 630 |
final_composition,
|
| 631 |
-
generated_batches,
|
| 632 |
-
block_lines,
|
| 633 |
model_selector
|
| 634 |
],
|
| 635 |
outputs
|
| 636 |
)
|
| 637 |
|
| 638 |
-
gr.Markdown("## Add/Remove Batch")
|
| 639 |
-
batch_number = gr.Slider(0, NUM_OUT_BATCHES - 1, value=0, step=1, label="Batch number to add/remove")
|
| 640 |
-
add_btn = gr.Button("Add batch", variant="primary")
|
| 641 |
-
remove_btn = gr.Button("Remove batch", variant="stop")
|
| 642 |
-
clear_btn = gr.ClearButton()
|
| 643 |
-
|
| 644 |
-
final_audio_output = gr.Audio(label="Final MIDI audio", format=AUDIO_FORMAT)
|
| 645 |
-
final_plot_output = gr.Plot(label="Final MIDI plot")
|
| 646 |
-
final_file_output = gr.File(label="Final MIDI file")
|
| 647 |
-
|
| 648 |
-
add_btn.click(
|
| 649 |
-
add_batch,
|
| 650 |
-
[batch_number, final_composition, generated_batches, block_lines],
|
| 651 |
-
[final_audio_output, final_plot_output, final_file_output, final_composition, generated_batches, block_lines]
|
| 652 |
-
)
|
| 653 |
-
remove_btn.click(
|
| 654 |
-
remove_batch,
|
| 655 |
-
[batch_number, num_gen_tokens, final_composition, generated_batches, block_lines],
|
| 656 |
-
[final_audio_output, final_plot_output, final_file_output, final_composition, generated_batches, block_lines]
|
| 657 |
-
)
|
| 658 |
-
clear_btn.click(clear, inputs=None,
|
| 659 |
-
outputs=[final_audio_output, final_plot_output, final_file_output, final_composition, block_lines])
|
| 660 |
-
|
| 661 |
# -----------------------------
|
| 662 |
# APP LAUNCHER
|
| 663 |
# -----------------------------
|
| 664 |
if __name__ == "__main__":
|
| 665 |
-
|
| 666 |
mcp_server=RUNNING_IN_SPACE, # MCP only on HF
|
| 667 |
share=not RUNNING_IN_SPACE, # Share only locally
|
| 668 |
server_name="0.0.0.0",
|
|
|
|
| 1 |
+
#==========================================================
|
| 2 |
# https://huggingface.co/spaces/asigalov61/Orpheus-Morpheus
|
| 3 |
+
#==========================================================
|
| 4 |
|
| 5 |
# -----------------------------
|
| 6 |
# CONFIGURATION & GLOBALS
|
|
|
|
| 522 |
|
| 523 |
return [final_composition] + outputs_flat
|
| 524 |
|
| 525 |
+
# -----------------------------
|
| 526 |
+
# MISC FUNCTIONS
|
| 527 |
+
# -----------------------------
|
| 528 |
+
def reset(final_composition=[]):
|
| 529 |
+
"""Reset composition state."""
|
| 530 |
+
print_sep()
|
| 531 |
+
print('Reset composition...')
|
| 532 |
+
print_sep()
|
| 533 |
+
return []
|
| 534 |
+
|
| 535 |
# -----------------------------
|
| 536 |
# GRADIO INTERFACE SETUP
|
| 537 |
# -----------------------------
|
|
|
|
| 581 |
gr.Markdown("## Upload seed MIDI or click 'Generate' button for random output")
|
| 582 |
|
| 583 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
| 584 |
+
input_midi.upload(reset, [final_composition],
|
| 585 |
+
[final_composition])
|
| 586 |
|
| 587 |
gr.Markdown("## Generation options")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 588 |
|
| 589 |
+
num_prime_tokens = gr.Slider(0, 32, value=0, step=1, label="Number of prime tokens")
|
| 590 |
+
num_gen_tokens = gr.Slider(256, 1280, value=1280, step=1, label="Number of tokens to generate")
|
| 591 |
requested_model = gr.Dropdown(label="Model to use",
|
| 592 |
choices=list(models_dict.keys()),
|
| 593 |
value=list(models_dict.keys())[0],
|
|
|
|
| 594 |
)
|
| 595 |
model_temperature = gr.Slider(0.1, 1, value=0.9, step=0.01, label="Model temperature",
|
| 596 |
info="Increase for more creative output, decrease for more repetitive output"
|
|
|
|
| 598 |
model_top_p = gr.Slider(0.1, 1.0, value=0.96, step=0.01, label="Model sampling top p value",
|
| 599 |
info="1 == Disabled"
|
| 600 |
)
|
|
|
|
|
|
|
| 601 |
|
| 602 |
generate_btn = gr.Button("Generate", variant="primary")
|
| 603 |
|
| 604 |
gr.Markdown("## Batch Previews")
|
| 605 |
+
outputs = [final_composition]
|
| 606 |
# Two outputs (audio and plot) for each batch
|
| 607 |
for i in range(NUM_OUT_BATCHES):
|
| 608 |
with gr.Tab(f"Batch # {i}"):
|
|
|
|
| 610 |
plot_output = gr.Plot(label=f"Batch # {i} MIDI Plot")
|
| 611 |
midi_file = gr.File(label=f"Batch # {i} MIDI File")
|
| 612 |
outputs.extend([audio_output, plot_output, midi_file])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
|
| 614 |
generate_btn.click(
|
| 615 |
generate_music_and_state,
|
| 616 |
[input_midi,
|
|
|
|
| 617 |
num_prime_tokens,
|
| 618 |
num_gen_tokens,
|
| 619 |
model_temperature,
|
| 620 |
model_top_p,
|
|
|
|
|
|
|
| 621 |
final_composition,
|
|
|
|
|
|
|
| 622 |
model_selector
|
| 623 |
],
|
| 624 |
outputs
|
| 625 |
)
|
| 626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
# -----------------------------
|
| 628 |
# APP LAUNCHER
|
| 629 |
# -----------------------------
|
| 630 |
if __name__ == "__main__":
|
| 631 |
+
orpheus_morpheus_app.launch(
|
| 632 |
mcp_server=RUNNING_IN_SPACE, # MCP only on HF
|
| 633 |
share=not RUNNING_IN_SPACE, # Share only locally
|
| 634 |
server_name="0.0.0.0",
|