thecollabagepatch commited on
Commit
637c678
1 Parent(s): ee282eb

rearrange imports

Browse files
Files changed (4) hide show
  1. .vs/slnx.sqlite +0 -0
  2. app.py +2 -1
  3. app_backup.py +242 -0
  4. app_backup2.py +245 -0
.vs/slnx.sqlite ADDED
File without changes
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from musiclang_predict import MusicLangPredictor
3
  import random
4
  import subprocess
@@ -9,7 +10,7 @@ import numpy as np
9
  from audiocraft.models import MusicGen
10
  from audiocraft.data.audio import audio_write
11
  from pydub import AudioSegment
12
- import spaces
13
  import tempfile
14
  from pydub import AudioSegment
15
  import io
 
1
  import gradio as gr
2
+ import spaces
3
  from musiclang_predict import MusicLangPredictor
4
  import random
5
  import subprocess
 
10
  from audiocraft.models import MusicGen
11
  from audiocraft.data.audio import audio_write
12
  from pydub import AudioSegment
13
+
14
  import tempfile
15
  from pydub import AudioSegment
16
  import io
app_backup.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from musiclang_predict import MusicLangPredictor
3
+ import random
4
+ import subprocess
5
+ import os
6
+ import torchaudio
7
+ import torch
8
+ import numpy as np
9
+ from audiocraft.models import MusicGen
10
+ from audiocraft.data.audio import audio_write
11
+ from pydub import AudioSegment
12
+ import spaces
13
+
14
+
15
+ # Utility Functions
16
+ def peak_normalize(y, target_peak=0.97):
17
+ return target_peak * (y / np.max(np.abs(y)))
18
+
19
+ def rms_normalize(y, target_rms=0.05):
20
+ return y * (target_rms / np.sqrt(np.mean(y**2)))
21
+
22
+ def preprocess_audio(waveform):
23
+ waveform_np = waveform.cpu().squeeze().numpy() # Move to CPU before converting to NumPy
24
+ # processed_waveform_np = rms_normalize(peak_normalize(waveform_np))
25
+ return torch.from_numpy(waveform_np).unsqueeze(0).to(device)
26
+
27
+ def create_slices(song, sr, slice_duration, bpm, num_slices=5):
28
+ song_length = song.shape[-1] / sr
29
+ slices = []
30
+
31
+ # Ensure the first slice is from the beginning of the song
32
+ first_slice_waveform = song[..., :int(slice_duration * sr)]
33
+ slices.append(first_slice_waveform)
34
+
35
+ for i in range(1, num_slices):
36
+ possible_start_indices = list(range(int(slice_duration * sr), int(song_length * sr), int(4 * 60 / bpm * sr)))
37
+ if not possible_start_indices:
38
+ # If there are no valid start indices, duplicate the first slice
39
+ slices.append(first_slice_waveform)
40
+ continue
41
+
42
+ random_start = random.choice(possible_start_indices)
43
+ slice_end = random_start + int(slice_duration * sr)
44
+
45
+ if slice_end > song_length * sr:
46
+ # Wrap around to the beginning of the song
47
+ remaining_samples = int(slice_end - song_length * sr)
48
+ slice_waveform = torch.cat([song[..., random_start:], song[..., :remaining_samples]], dim=-1)
49
+ else:
50
+ slice_waveform = song[..., random_start:slice_end]
51
+
52
+ if len(slice_waveform.squeeze()) < int(slice_duration * sr):
53
+ additional_samples_needed = int(slice_duration * sr) - len(slice_waveform.squeeze())
54
+ slice_waveform = torch.cat([slice_waveform, song[..., :additional_samples_needed]], dim=-1)
55
+
56
+ slices.append(slice_waveform)
57
+
58
+ return slices
59
+
60
+ def calculate_duration(bpm, min_duration=29, max_duration=30):
61
+ single_bar_duration = 4 * 60 / bpm
62
+ bars = max(min_duration // single_bar_duration, 1)
63
+
64
+ while single_bar_duration * bars < min_duration:
65
+ bars += 1
66
+
67
+ duration = single_bar_duration * bars
68
+
69
+ while duration > max_duration and bars > 1:
70
+ bars -= 1
71
+ duration = single_bar_duration * bars
72
+
73
+ return duration
74
+
75
+ @spaces.GPU(duration=120)
76
+ def generate_music(seed, use_chords, chord_progression, prompt_duration, musicgen_model, num_iterations, bpm):
77
+ while True:
78
+ try:
79
+ if seed == "":
80
+ seed = random.randint(1, 10000)
81
+
82
+ ml = MusicLangPredictor('musiclang/musiclang-v2')
83
+
84
+ try:
85
+ seed = int(seed)
86
+ except ValueError:
87
+ seed = random.randint(1, 10000)
88
+
89
+ nb_tokens = 1024
90
+ temperature = 0.9
91
+ top_p = 1.0
92
+
93
+ if use_chords and chord_progression.strip():
94
+ score = ml.predict_chords(
95
+ chord_progression,
96
+ time_signature=(4, 4),
97
+ temperature=temperature,
98
+ topp=top_p,
99
+ rng_seed=seed
100
+ )
101
+ else:
102
+ score = ml.predict(
103
+ nb_tokens=nb_tokens,
104
+ temperature=temperature,
105
+ topp=top_p,
106
+ rng_seed=seed
107
+ )
108
+
109
+ midi_filename = f"output_{seed}.mid"
110
+ wav_filename = midi_filename.replace(".mid", ".wav")
111
+
112
+ score.to_midi(midi_filename, tempo=bpm, time_signature=(4, 4))
113
+
114
+ subprocess.run(["fluidsynth", "-ni", "font.sf2", midi_filename, "-F", wav_filename, "-r", "44100"])
115
+
116
+ # Load the generated audio
117
+ song, sr = torchaudio.load(wav_filename)
118
+ song = song.to(device)
119
+
120
+ # Use the user-provided BPM value for duration calculation
121
+ duration = calculate_duration(bpm)
122
+
123
+ # Create slices from the song using the user-provided BPM value
124
+ slices = create_slices(song, sr, 35, bpm, num_slices=5)
125
+
126
+ # Load the model
127
+ model_name = musicgen_model.split(" ")[0]
128
+ model_continue = MusicGen.get_pretrained(model_name)
129
+
130
+ # Setting generation parameters
131
+ model_continue.set_generation_params(
132
+ use_sampling=True,
133
+ top_k=250,
134
+ top_p=0.0,
135
+ temperature=1.0,
136
+ duration=duration,
137
+ cfg_coef=3
138
+ )
139
+
140
+ all_audio_files = []
141
+
142
+ for i in range(num_iterations):
143
+ slice_idx = i % len(slices)
144
+
145
+ print(f"Running iteration {i + 1} using slice {slice_idx}...")
146
+
147
+ prompt_waveform = slices[slice_idx][..., :int(prompt_duration * sr)]
148
+ prompt_waveform = preprocess_audio(prompt_waveform)
149
+
150
+ output = model_continue.generate_continuation(prompt_waveform, prompt_sample_rate=sr, progress=True)
151
+ output = output.cpu() # Move the output tensor back to CPU
152
+
153
+ # Make sure the output tensor has at most 2 dimensions
154
+ if len(output.size()) > 2:
155
+ output = output.squeeze()
156
+
157
+ filename_without_extension = f'continue_{i}'
158
+ filename_with_extension = f'{filename_without_extension}.wav'
159
+
160
+ audio_write(filename_with_extension, output, model_continue.sample_rate, strategy="loudness", loudness_compressor=True)
161
+ all_audio_files.append(f'{filename_without_extension}.wav.wav') # Assuming the library appends an extra .wav
162
+
163
+ # Combine all audio files
164
+ combined_audio = AudioSegment.empty()
165
+ for filename in all_audio_files:
166
+ combined_audio += AudioSegment.from_wav(filename)
167
+
168
+ combined_audio_filename = f"combined_audio_{seed}.mp3"
169
+ combined_audio.export(combined_audio_filename, format="mp3")
170
+
171
+ # Clean up temporary files
172
+ os.remove(midi_filename)
173
+ os.remove(wav_filename)
174
+ for filename in all_audio_files:
175
+ os.remove(filename)
176
+
177
+ return combined_audio_filename
178
+ except IndexError:
179
+ # Retry with a new random seed if an IndexError is raised
180
+ seed = random.randint(1, 10000)
181
+
182
+ # Check if CUDA is available
183
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
184
+
185
+ # Define the expandable sections
186
+ musiclang_blurb = """
187
+ ## musiclang
188
+ musiclang is a controllable ai midi model. it can generate midi sequences based on user-provided parameters, or unconditionally.
189
+ [<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" width="20" style="vertical-align:middle"> musiclang github](https://github.com/MusicLang/musiclang_predict)
190
+ [<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="Hugging Face" width="20" style="vertical-align:middle"> musiclang huggingface space](https://huggingface.co/spaces/musiclang/musiclang-predict)
191
+ """
192
+
193
+ musicgen_blurb = """
194
+ ## musicgen
195
+ musicgen is a transformer-based music model that generates audio. It can also do something called a continuation, which was initially meant to extend musicgen outputs beyond 30 seconds. it can be used with any input audio to produce surprising results.
196
+ [<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" width="20" style="vertical-align:middle"> audiocraft github](https://github.com/facebookresearch/audiocraft)
197
+ visit https://thecollabagepatch.com/infinitepolo.mp3 or https://thecollabagepatch.com/audiocraft.mp3 to hear continuations in action.
198
+ see also https://youtube.com/@thecollabagepatch
199
+ """
200
+
201
+ finetunes_blurb = """
202
+ ## fine-tuned models
203
+ the fine-tunes hosted on the huggingface hub are provided collectively by the musicgen discord community. thanks to vanya, mj, hoenn, septicDNB and of course, lyra.
204
+ [<img src="https://cdn.iconscout.com/icon/free/png-256/discord-3691244-3073764.png" alt="Discord" width="20" style="vertical-align:middle"> musicgen discord](https://discord.gg/93kX8rGZ)
205
+ [<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" style="vertical-align:middle"> fine-tuning colab notebook by lyra](https://colab.research.google.com/drive/13tbcC3A42KlaUZ21qvUXd25SFLu8WIvb)
206
+ """
207
+
208
+ # Create the Gradio interface
209
+ with gr.Blocks() as iface:
210
+ gr.Markdown("# the-slot-machine")
211
+ gr.Markdown("two ai's jamming. warning: outputs will be very strange, likely stupid, and possibly rad.")
212
+ gr.Markdown("this is a musical slot machine. using musiclang, we get a midi output. then, we let a musicgen model continue, semi-randomly, from different sections of the midi track. the slot machine combines em all at the end into something very bizarre. pick a number for the seed between 1 and 10k, or leave it blank to unlock the full rnjesus powers. if you wanna be lame, you can control the chord progression, prompt duration, musicgen model, number of iterations, and BPM.")
213
+
214
+ with gr.Accordion("more info", open=False):
215
+ gr.Markdown(musiclang_blurb)
216
+ gr.Markdown(musicgen_blurb)
217
+ gr.Markdown(finetunes_blurb)
218
+
219
+ with gr.Row():
220
+ with gr.Column():
221
+ seed = gr.Textbox(label="seed (leave blank for random)", value="")
222
+ use_chords = gr.Checkbox(label="control chord progression", value=False)
223
+ chord_progression = gr.Textbox(label="chord progression (e.g., Am CM Dm E7 Am)", visible=True)
224
+ prompt_duration = gr.Dropdown(label="prompt duration (seconds)", choices=list(range(1, 11)), value=7)
225
+ musicgen_models = [
226
+ "thepatch/vanya_ai_dnb_0.1 (small)",
227
+ "thepatch/budots_remix (small)",
228
+ "thepatch/PhonkV2 (small)",
229
+ "thepatch/bleeps-medium (medium)",
230
+ "thepatch/hoenn_lofi (large)"
231
+ ]
232
+
233
+ musicgen_model = gr.Dropdown(label="musicGen model", choices=musicgen_models, value=musicgen_models[0])
234
+ num_iterations = gr.Slider(label="number of iterations", minimum=1, maximum=10, step=1, value=3)
235
+ bpm = gr.Slider(label="BPM", minimum=60, maximum=200, step=1, value=140)
236
+ generate_button = gr.Button("generate music")
237
+ with gr.Column():
238
+ output_audio = gr.Audio(label="your track")
239
+
240
+ generate_button.click(generate_music, inputs=[seed, use_chords, chord_progression, prompt_duration, musicgen_model, num_iterations, bpm], outputs=output_audio)
241
+
242
+ iface.launch()
app_backup2.py ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from musiclang_predict import MusicLangPredictor
3
+ import random
4
+ import subprocess
5
+ import os
6
+ import torchaudio
7
+ import torch
8
+ import numpy as np
9
+ from audiocraft.models import MusicGen
10
+ from audiocraft.data.audio import audio_write
11
+ from pydub import AudioSegment
12
+ import spaces
13
+ import tempfile
14
+
15
+ # Check if CUDA is available
16
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
+
18
+ # Utility Functions
19
+ def peak_normalize(y, target_peak=0.97):
20
+ return target_peak * (y / np.max(np.abs(y)))
21
+
22
+ def rms_normalize(y, target_rms=0.05):
23
+ return y * (target_rms / np.sqrt(np.mean(y**2)))
24
+
25
+ def preprocess_audio(waveform):
26
+ waveform_np = waveform.cpu().squeeze().numpy() # Move to CPU before converting to NumPy
27
+ # processed_waveform_np = rms_normalize(peak_normalize(waveform_np))
28
+ return torch.from_numpy(waveform_np).unsqueeze(0).to(device)
29
+
30
+ def create_slices(song, sr, slice_duration, bpm, num_slices=5):
31
+ song_length = song.shape[-1] / sr
32
+ slices = []
33
+
34
+ # Ensure the first slice is from the beginning of the song
35
+ first_slice_waveform = song[..., :int(slice_duration * sr)]
36
+ slices.append(first_slice_waveform)
37
+
38
+ for i in range(1, num_slices):
39
+ possible_start_indices = list(range(int(slice_duration * sr), int(song_length * sr), int(4 * 60 / bpm * sr)))
40
+ if not possible_start_indices:
41
+ # If there are no valid start indices, duplicate the first slice
42
+ slices.append(first_slice_waveform)
43
+ continue
44
+
45
+ random_start = random.choice(possible_start_indices)
46
+ slice_end = random_start + int(slice_duration * sr)
47
+
48
+ if slice_end > song_length * sr:
49
+ # Wrap around to the beginning of the song
50
+ remaining_samples = int(slice_end - song_length * sr)
51
+ slice_waveform = torch.cat([song[..., random_start:], song[..., :remaining_samples]], dim=-1)
52
+ else:
53
+ slice_waveform = song[..., random_start:slice_end]
54
+
55
+ if len(slice_waveform.squeeze()) < int(slice_duration * sr):
56
+ additional_samples_needed = int(slice_duration * sr) - len(slice_waveform.squeeze())
57
+ slice_waveform = torch.cat([slice_waveform, song[..., :additional_samples_needed]], dim=-1)
58
+
59
+ slices.append(slice_waveform)
60
+
61
+ return slices
62
+
63
+ def calculate_duration(bpm, min_duration=29, max_duration=30):
64
+ single_bar_duration = 4 * 60 / bpm
65
+ bars = max(min_duration // single_bar_duration, 1)
66
+
67
+ while single_bar_duration * bars < min_duration:
68
+ bars += 1
69
+
70
+ duration = single_bar_duration * bars
71
+
72
+ while duration > max_duration and bars > 1:
73
+ bars -= 1
74
+ duration = single_bar_duration * bars
75
+
76
+ return duration
77
+
78
+ @spaces.GPU(duration=60)
79
+ def generate_midi(seed, use_chords, chord_progression, bpm):
80
+ if seed == "":
81
+ seed = random.randint(1, 10000)
82
+
83
+ ml = MusicLangPredictor('musiclang/musiclang-v2')
84
+
85
+ try:
86
+ seed = int(seed)
87
+ except ValueError:
88
+ seed = random.randint(1, 10000)
89
+
90
+ nb_tokens = 1024
91
+ temperature = 0.9
92
+ top_p = 1.0
93
+
94
+ if use_chords and chord_progression.strip():
95
+ score = ml.predict_chords(
96
+ chord_progression,
97
+ time_signature=(4, 4),
98
+ temperature=temperature,
99
+ topp=top_p,
100
+ rng_seed=seed
101
+ )
102
+ else:
103
+ score = ml.predict(
104
+ nb_tokens=nb_tokens,
105
+ temperature=temperature,
106
+ topp=top_p,
107
+ rng_seed=seed
108
+ )
109
+
110
+ midi_filename = f"output_{seed}.mid"
111
+ wav_filename = midi_filename.replace(".mid", ".wav")
112
+
113
+ score.to_midi(midi_filename, tempo=bpm, time_signature=(4, 4))
114
+
115
+ subprocess.run(["fluidsynth", "-ni", "font.sf2", midi_filename, "-F", wav_filename, "-r", "44100"])
116
+
117
+ # Clean up temporary MIDI file
118
+ os.remove(midi_filename)
119
+
120
+ sample_rate = 44100 # Assuming fixed sample rate from fluidsynth command
121
+ return wav_filename
122
+
123
+ @spaces.GPU(duration=120)
124
+ def generate_music(wav_filename, prompt_duration, musicgen_model, num_iterations, bpm):
125
+ # Load the audio from the passed file path
126
+ song, sr = torchaudio.load(wav_filename)
127
+ song = song.to(device)
128
+ # Use the user-provided BPM value for duration calculation
129
+ duration = calculate_duration(bpm)
130
+
131
+ # Create slices from the song using the user-provided BPM value
132
+ slices = create_slices(song, sr, 35, bpm, num_slices=5)
133
+
134
+ # Load the model
135
+ model_name = musicgen_model.split(" ")[0]
136
+ model_continue = MusicGen.get_pretrained(model_name)
137
+
138
+ # Setting generation parameters
139
+ model_continue.set_generation_params(
140
+ use_sampling=True,
141
+ top_k=250,
142
+ top_p=0.0,
143
+ temperature=1.0,
144
+ duration=duration,
145
+ cfg_coef=3
146
+ )
147
+
148
+ all_audio_files = []
149
+
150
+ for i in range(num_iterations):
151
+ slice_idx = i % len(slices)
152
+
153
+ print(f"Running iteration {i + 1} using slice {slice_idx}...")
154
+
155
+ prompt_waveform = slices[slice_idx][..., :int(prompt_duration * sr)]
156
+ prompt_waveform = preprocess_audio(prompt_waveform)
157
+
158
+ output = model_continue.generate_continuation(prompt_waveform, prompt_sample_rate=sr, progress=True)
159
+ output = output.cpu() # Move the output tensor back to CPU
160
+
161
+ # Make sure the output tensor has at most 2 dimensions
162
+ if len(output.size()) > 2:
163
+ output = output.squeeze()
164
+
165
+ filename_without_extension = f'continue_{i}'
166
+ filename_with_extension = f'{filename_without_extension}.wav'
167
+
168
+ audio_write(filename_with_extension, output, model_continue.sample_rate, strategy="loudness", loudness_compressor=True)
169
+ all_audio_files.append(f'{filename_without_extension}.wav.wav') # Assuming the library appends an extra .wav
170
+
171
+ # Combine all audio files
172
+ combined_audio = AudioSegment.empty()
173
+ for filename in all_audio_files:
174
+ combined_audio += AudioSegment.from_wav(filename)
175
+
176
+ combined_audio_filename = f"combined_audio_{random.randint(1, 10000)}.mp3"
177
+ combined_audio.export(combined_audio_filename, format="mp3")
178
+
179
+ # Clean up temporary files
180
+ for filename in all_audio_files:
181
+ os.remove(filename)
182
+
183
+ return combined_audio_filename
184
+
185
+ # Define the expandable sections
186
+ musiclang_blurb = """
187
+ ## musiclang
188
+ musiclang is a controllable ai midi model. it can generate midi sequences based on user-provided parameters, or unconditionally.
189
+ [<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" width="20" style="vertical-align:middle"> musiclang github](https://github.com/MusicLang/musiclang_predict)
190
+ [<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="Hugging Face" width="20" style="vertical-align:middle"> musiclang huggingface space](https://huggingface.co/spaces/musiclang/musiclang-predict)
191
+ """
192
+
193
+ musicgen_blurb = """
194
+ ## musicgen
195
+ musicgen is a transformer-based music model that generates audio. It can also do something called a continuation, which was initially meant to extend musicgen outputs beyond 30 seconds. it can be used with any input audio to produce surprising results.
196
+ [<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" width="20" style="vertical-align:middle"> audiocraft github](https://github.com/facebookresearch/audiocraft)
197
+ visit https://thecollabagepatch.com/infinitepolo.mp3 or https://thecollabagepatch.com/audiocraft.mp3 to hear continuations in action.
198
+ see also https://youtube.com/@thecollabagepatch
199
+ """
200
+
201
+ finetunes_blurb = """
202
+ ## fine-tuned models
203
+ the fine-tunes hosted on the huggingface hub are provided collectively by the musicgen discord community. thanks to vanya, mj, hoenn, septicDNB and of course, lyra.
204
+ [<img src="https://cdn.iconscout.com/icon/free/png-256/discord-3691244-3073764.png" alt="Discord" width="20" style="vertical-align:middle"> musicgen discord](https://discord.gg/93kX8rGZ)
205
+ [<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" style="vertical-align:middle"> fine-tuning colab notebook by lyra](https://colab.research.google.com/drive/13tbcC3A42KlaUZ21qvUXd25SFLu8WIvb)
206
+ """
207
+
208
+ # Create the Gradio interface
209
+ with gr.Blocks() as iface:
210
+ gr.Markdown("# the-slot-machine")
211
+ gr.Markdown("two ai's jamming. warning: outputs will be very strange, likely stupid, and possibly rad.")
212
+ gr.Markdown("this is a musical slot machine. using musiclang, we get a midi output. then, we let a musicgen model continue, semi-randomly, from different sections of the midi track. the slot machine combines em all at the end into something very bizarre. pick a number for the seed between 1 and 10k, or leave it blank to unlock the full rnjesus powers. if you wanna be lame, you can control the chord progression, prompt duration, musicgen model, number of iterations, and BPM.")
213
+
214
+ with gr.Accordion("more info", open=False):
215
+ gr.Markdown(musiclang_blurb)
216
+ gr.Markdown(musicgen_blurb)
217
+ gr.Markdown(finetunes_blurb)
218
+
219
+ with gr.Row():
220
+ with gr.Column():
221
+ seed = gr.Textbox(label="Seed (leave blank for random)", value="")
222
+ use_chords = gr.Checkbox(label="Control Chord Progression", value=False)
223
+ chord_progression = gr.Textbox(label="Chord Progression (e.g., Am CM Dm E7 Am)", visible=True)
224
+ bpm = gr.Slider(label="BPM", minimum=60, maximum=200, step=1, value=120)
225
+ generate_midi_button = gr.Button("Generate MIDI")
226
+ midi_audio = gr.Audio(label="Generated MIDI Audio", type="filepath") # Ensure this is set to handle file paths
227
+
228
+ with gr.Column():
229
+ prompt_duration = gr.Dropdown(label="Prompt Duration (seconds)", choices=list(range(1, 11)), value=5)
230
+ musicgen_model = gr.Dropdown(label="MusicGen Model", choices=[
231
+ "thepatch/vanya_ai_dnb_0.1 (small)",
232
+ "thepatch/budots_remix (small)",
233
+ "thepatch/PhonkV2 (small)",
234
+ "thepatch/bleeps-medium (medium)",
235
+ "thepatch/hoenn_lofi (large)"
236
+ ], value="thepatch/vanya_ai_dnb_0.1 (small)")
237
+ num_iterations = gr.Slider(label="Number of Iterations", minimum=1, maximum=3, step=1, value=3)
238
+ generate_music_button = gr.Button("Generate Music")
239
+ output_audio = gr.Audio(label="Generated Music")
240
+
241
+ # Connecting the components
242
+ generate_midi_button.click(generate_midi, inputs=[seed, use_chords, chord_progression, bpm], outputs=[midi_audio])
243
+ generate_music_button.click(generate_music, inputs=[midi_audio, prompt_duration, musicgen_model, num_iterations, bpm], outputs=[output_audio])
244
+
245
+ iface.launch()