Spaces:
Runtime error
Runtime error
File size: 5,479 Bytes
d8fad2b 85220e3 d8fad2b 013f12b 735366b 3356573 013f12b 0c19dbc 3356573 4e7a676 0c19dbc 3356573 4e7a676 3356573 4e7a676 0c19dbc 3356573 735366b 3356573 d8fad2b 3356573 d8fad2b 85220e3 d8fad2b eb5d565 42739f2 d8fad2b b85b5a2 d8fad2b 42739f2 d8fad2b 42739f2 d8fad2b 7c7327d d8fad2b 85220e3 d8fad2b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
import os
import gradio as gr
from utils import (
generate_song,
remove_last_instrument,
regenerate_last_instrument,
change_tempo,
)
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
DESCRIPTION = """
<h1>🎵 Multitrack Midi Generator 🎶</h1>
<h3>AI-driven Music Composer: Creating Music One Instrument at a Time!</h3>
<p>This interactive application uses an AI model to generate music sequences based on a chosen genre and various user inputs. The apps constructs the piece instrument by instrument</p>
<div style="display: flex; justify-content: space-between;">
<div style="width: 45%; margin-right: 5%;">
<h2>Features:</h2>
<ul>
<li>🎼 Select the genre for the music.</li>
<li>🌡️ Use the "Temperature" slider to adjust the randomness of the music generated (higher values will produce more random outputs).</li>
<li>⏱️ Adjust the "Tempo" slider to change the speed of the music.</li>
<li>🎹 Use the buttons to generate a new song from scratch, continue generation with the current settings, remove the last added instrument, regenerate the last added instrument with a new one, or change the tempo of the current song.</li>
</ul>
</div>
<div style="width: 45%; margin-left: 5%;">
<h2>Outputs:</h2>
<p>The app outputs the following:</p>
<ul>
<li>🎧 The audio of the generated song.</li>
<li>📁 A MIDI file of the song.</li>
<li>📊 A plot of the song's sequence.</li>
<li>🎸 A list of the generated instruments.</li>
<li>📝 The text sequence of the song.</li>
</ul>
</div>
</div>
<hr style="margin-top: 2em; margin-bottom: 2em;">
<p>This application is built upon the inspiring work of <a href="https://www.linkedin.com/in/dr-tristan-behrens-734967a2" target="_blank">Dr. Tristan Behrens</a></p>
<p>Enjoy creating your own music!</p>
"""
genres = ["ROCK", "POP", "OTHER", "R&B/SOUL", "JAZZ", "ELECTRONIC", "RANDOM"]
demo = gr.Blocks()
def run():
with demo:
gr.HTML(DESCRIPTION)
gr.DuplicateButton(value="Duplicate Space for private use")
with gr.Row():
with gr.Column():
temp = gr.Slider(
minimum=0, maximum=1, step=0.05, value=0.85, label="Temperature"
)
genre = gr.Dropdown(
choices=genres, value="POP", label="Select the genre"
)
with gr.Row():
btn_from_scratch = gr.Button("🧹 Start from scratch")
btn_continue = gr.Button("➡️ Continue Generation")
btn_remove_last = gr.Button("↩️ Remove last instrument")
btn_regenerate_last = gr.Button("🔄 Regenerate last instrument")
with gr.Column():
with gr.Box():
audio_output = gr.Video(show_share_button=True)
midi_file = gr.File()
with gr.Row():
qpm = gr.Slider(
minimum=60, maximum=140, step=10, value=120, label="Tempo"
)
btn_qpm = gr.Button("Change Tempo")
with gr.Row():
with gr.Column():
plot_output = gr.Plot()
with gr.Column():
instruments_output = gr.Markdown("# List of generated instruments")
with gr.Row():
text_sequence = gr.Text()
empty_sequence = gr.Text(visible=False)
with gr.Row():
num_tokens = gr.Text(visible=False)
btn_from_scratch.click(
fn=generate_song,
inputs=[genre, temp, empty_sequence, qpm],
outputs=[
audio_output,
midi_file,
plot_output,
instruments_output,
text_sequence,
num_tokens,
],
)
btn_continue.click(
fn=generate_song,
inputs=[genre, temp, text_sequence, qpm],
outputs=[
audio_output,
midi_file,
plot_output,
instruments_output,
text_sequence,
num_tokens,
],
)
btn_remove_last.click(
fn=remove_last_instrument,
inputs=[text_sequence, qpm],
outputs=[
audio_output,
midi_file,
plot_output,
instruments_output,
text_sequence,
num_tokens,
],
)
btn_regenerate_last.click(
fn=regenerate_last_instrument,
inputs=[text_sequence, qpm],
outputs=[
audio_output,
midi_file,
plot_output,
instruments_output,
text_sequence,
num_tokens,
],
)
btn_qpm.click(
fn=change_tempo,
inputs=[text_sequence, qpm],
outputs=[
audio_output,
midi_file,
plot_output,
instruments_output,
text_sequence,
num_tokens,
],
)
demo.launch(server_name="0.0.0.0", server_port=7860)
if __name__ == "__main__":
run()
|