Spaces:
Sleeping
Sleeping
floriangardin
commited on
Commit
·
a906ae7
1
Parent(s):
d8926bd
choose chord progression
Browse files
app.py
CHANGED
@@ -3,17 +3,32 @@ from musiclang_predict import MusicLangPredictor # Assuming this is the correct
|
|
3 |
from midi2audio import FluidSynth
|
4 |
import os
|
5 |
|
6 |
-
|
7 |
-
def musiclang():
|
8 |
-
nb_tokens = 1024
|
9 |
-
temperature = 0.9
|
10 |
top_p = 1.0
|
11 |
-
seed =
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Initialize the MusicLangPredictor
|
14 |
ml = MusicLangPredictor('musiclang/musiclang-v2')
|
15 |
# Generate the score
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Save the score as a MIDI file
|
19 |
midi_path = 'test.mid'
|
@@ -27,16 +42,27 @@ def musiclang():
|
|
27 |
os.system(f'ffmpeg -i {wav_path} -acodec libmp3lame -y -loglevel quiet -stats {mp3_path}')
|
28 |
|
29 |
# Return the path to the MP3 for Gradio to display
|
30 |
-
return mp3_path
|
31 |
|
|
|
|
|
32 |
|
33 |
-
# Gradio interface
|
34 |
iface = gr.Interface(
|
35 |
fn=musiclang,
|
36 |
-
inputs=
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
title="Music Generation with MusicLang",
|
39 |
-
description="
|
|
|
|
|
40 |
)
|
41 |
|
42 |
iface.launch()
|
|
|
3 |
from midi2audio import FluidSynth
|
4 |
import os
|
5 |
|
6 |
+
def musiclang(nb_tokens, temperature, chord_progression):
|
|
|
|
|
|
|
7 |
top_p = 1.0
|
8 |
+
seed = 0
|
9 |
+
|
10 |
+
# If chord progression is empty, we might set it to None or handle it accordingly
|
11 |
+
if chord_progression.strip() == "":
|
12 |
+
chord_progression = None # Assuming the predictor can handle None as "generate freely"
|
13 |
|
14 |
# Initialize the MusicLangPredictor
|
15 |
ml = MusicLangPredictor('musiclang/musiclang-v2')
|
16 |
# Generate the score
|
17 |
+
if chord_progression is None or chord_progression.strip() == "":
|
18 |
+
score = ml.predict(
|
19 |
+
nb_tokens=int(nb_tokens),
|
20 |
+
temperature=float(temperature),
|
21 |
+
topp=top_p,
|
22 |
+
chord_progression=chord_progression, # Pass the chord progression, can be None
|
23 |
+
rng_seed=seed
|
24 |
+
)
|
25 |
+
else:
|
26 |
+
score = ml.predict_chords(
|
27 |
+
chord_progression,
|
28 |
+
time_signature=(4, 4),
|
29 |
+
temperature=temperature,
|
30 |
+
topp=top_p,
|
31 |
+
rng_seed=seed)
|
32 |
|
33 |
# Save the score as a MIDI file
|
34 |
midi_path = 'test.mid'
|
|
|
42 |
os.system(f'ffmpeg -i {wav_path} -acodec libmp3lame -y -loglevel quiet -stats {mp3_path}')
|
43 |
|
44 |
# Return the path to the MP3 for Gradio to display
|
|
|
45 |
|
46 |
+
# Return both the MP3 path for Gradio to display and the MIDI file path for download
|
47 |
+
return mp3_path, midi_path
|
48 |
|
49 |
+
# Gradio interface with inputs for temperature, nb_tokens, chord progression, and tempo
|
50 |
iface = gr.Interface(
|
51 |
fn=musiclang,
|
52 |
+
inputs=[
|
53 |
+
gr.Number(label="Number of Tokens", value=1024, min_value=256, max_value=2048, step=256),
|
54 |
+
gr.Slider(label="Temperature", value=0.9, minimum=0.1, maximum=1.0, step=0.1),
|
55 |
+
gr.Textbox(label="Chord Progression", placeholder="Am CM Dm/F E7 Am", lines=2, default=""),
|
56 |
+
gr.Slider(label="Tempo", value=120, minimum=60, maximum=240, step=1)
|
57 |
+
],
|
58 |
+
outputs=[
|
59 |
+
gr.Audio(label="Generated Music"),
|
60 |
+
gr.File(label="Download MIDI")
|
61 |
+
],
|
62 |
title="Music Generation with MusicLang",
|
63 |
+
description="""Customize the music generation by specifying the number of tokens, temperature, chord progression, and tempo.
|
64 |
+
\nChord qualities: M, m, 7, m7b5, sus2, sus4, m7, M7, dim, dim7. You can also specify the bass if it belongs to the chord (e.g., Bm/D).
|
65 |
+
\nIf no chord progression is given, it generates a free sample with the specified number of tokens."""
|
66 |
)
|
67 |
|
68 |
iface.launch()
|