Spaces:
Sleeping
Sleeping
Commit
•
d878645
1
Parent(s):
4b77a87
add examples with app
Browse files- .gitignore +3 -2
- app.py +69 -42
- flagged/log.csv +0 -2
.gitignore
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
.idea/
|
3 |
*.mid
|
4 |
venv/
|
5 |
-
*.mid
|
6 |
*.wav
|
7 |
-
|
|
|
|
|
|
2 |
.idea/
|
3 |
*.mid
|
4 |
venv/
|
|
|
5 |
*.wav
|
6 |
+
!examples/
|
7 |
+
*.mp3
|
8 |
+
gradio_cached_examples/
|
app.py
CHANGED
@@ -6,16 +6,14 @@ import os
|
|
6 |
import tempfile
|
7 |
|
8 |
|
9 |
-
def inner_loop(
|
10 |
top_p = 0.98
|
11 |
seed = 0
|
12 |
-
|
13 |
-
print(midi_file)
|
14 |
# Initialize the MusicLangPredictor
|
15 |
ml = MusicLangPredictor('musiclang/musiclang-v2')
|
16 |
tempo_message = "" # Default message if no MIDI file is uploaded
|
17 |
time_signature = (4, 4)
|
18 |
-
if midi_file is not None:
|
19 |
# Load the MIDI file and use it as the score prompt
|
20 |
filepath = midi_file
|
21 |
start_bar, end_bar = map(int, bar_range.split("-"))
|
@@ -76,47 +74,76 @@ def inner_loop(nb_tokens, temperature, chord_progression, tempo, midi_file, bar_
|
|
76 |
|
77 |
return mp3_path, midi_path, chord_repr, tempo_message
|
78 |
|
79 |
-
def musiclang(
|
80 |
exception = None
|
81 |
mp3_path, midi_path, chord_repr, tempo_message = None, None, None, ""
|
82 |
try:
|
83 |
-
mp3_path, midi_path, chord_repr, tempo_message = inner_loop(
|
84 |
-
midi_file, bar_range)
|
85 |
except Exception as e:
|
86 |
exception = "Error : " + e.__class__.__name__ + " " + str(e)
|
87 |
# Return the MP3 path for Gradio to display and the MIDI file path for download
|
88 |
-
return mp3_path, midi_path,
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import tempfile
|
7 |
|
8 |
|
9 |
+
def inner_loop(midi_file, chord_progression, tempo, temperature, nb_tokens, bar_range):
|
10 |
top_p = 0.98
|
11 |
seed = 0
|
|
|
|
|
12 |
# Initialize the MusicLangPredictor
|
13 |
ml = MusicLangPredictor('musiclang/musiclang-v2')
|
14 |
tempo_message = "" # Default message if no MIDI file is uploaded
|
15 |
time_signature = (4, 4)
|
16 |
+
if midi_file is not None and midi_file != "":
|
17 |
# Load the MIDI file and use it as the score prompt
|
18 |
filepath = midi_file
|
19 |
start_bar, end_bar = map(int, bar_range.split("-"))
|
|
|
74 |
|
75 |
return mp3_path, midi_path, chord_repr, tempo_message
|
76 |
|
77 |
+
def musiclang(midi_file, chord_progression, tempo, temperature, nb_tokens, bar_range):
|
78 |
exception = None
|
79 |
mp3_path, midi_path, chord_repr, tempo_message = None, None, None, ""
|
80 |
try:
|
81 |
+
mp3_path, midi_path, chord_repr, tempo_message = inner_loop(midi_file, chord_progression, tempo, temperature, nb_tokens, bar_range)
|
|
|
82 |
except Exception as e:
|
83 |
exception = "Error : " + e.__class__.__name__ + " " + str(e)
|
84 |
# Return the MP3 path for Gradio to display and the MIDI file path for download
|
85 |
+
return mp3_path, midi_path, exception
|
86 |
+
|
87 |
+
|
88 |
+
with gr.Blocks() as demo:
|
89 |
+
# Introductory text
|
90 |
+
gr.Markdown("""
|
91 |
+
# Controllable Symbolic Music Generation with MusicLang Predict
|
92 |
+
[MusicLang Predict](https://github.com/musiclang/musiclang_predict) offers advanced controllability features and high-quality music generation by manipulating symbolic music.
|
93 |
+
You can for example use it to continue your composition with a specific chord progression.
|
94 |
+
""")
|
95 |
+
|
96 |
+
with gr.Row():
|
97 |
+
with gr.Column():
|
98 |
+
with gr.Row():
|
99 |
+
midi_file = gr.File(label="Prompt MIDI File (Optional)", type="filepath", file_types=[".mid", ".midi"],
|
100 |
+
elem_id='midi_file_input')
|
101 |
+
with gr.Column():
|
102 |
+
bar_range = gr.Textbox(label="Bar Range of input file (eg: 0-4 for first four bars)", placeholder="0-4",
|
103 |
+
value="0-4", elem_id='bar_range_input')
|
104 |
+
nb_tokens = gr.Number(label="Nb Tokens",
|
105 |
+
value=512, minimum=256, maximum=2048, step=256, elem_id='nb_tokens_input')
|
106 |
+
temperature = gr.Slider(
|
107 |
+
label="Temperature",
|
108 |
+
value=0.95,
|
109 |
+
visible=False,
|
110 |
+
minimum=0.1, maximum=1.0, step=0.1, elem_id='temperature_input')
|
111 |
+
tempo = gr.Slider(label="Tempo", value=120, minimum=60, maximum=240, step=1, elem_id='tempo_input')
|
112 |
+
|
113 |
+
with gr.Row():
|
114 |
+
chord_progression = gr.Textbox(
|
115 |
+
label="Chord Progression (Optional)",
|
116 |
+
placeholder="Am CM Dm7/F E7 Asus4", lines=2, value="", elem_id='chord_progression_input')
|
117 |
+
|
118 |
+
with gr.Row():
|
119 |
+
generate_btn = gr.Button("Generate", elem_id='generate_button')
|
120 |
+
|
121 |
+
with gr.Column():
|
122 |
+
info_message = gr.Textbox(label="Info Message", elem_id='info_message_output')
|
123 |
+
generated_music = gr.Audio(label="Preview generated Music", elem_id='generated_music_output')
|
124 |
+
generated_midi = gr.File(label="Download MIDI", elem_id='generated_midi_output')
|
125 |
+
generate_btn.click(
|
126 |
+
fn=musiclang,
|
127 |
+
inputs=[midi_file, chord_progression, tempo, temperature, nb_tokens, bar_range],
|
128 |
+
outputs=[generated_music, generated_midi, info_message]
|
129 |
+
)
|
130 |
+
|
131 |
+
with gr.Row():
|
132 |
+
with gr.Column():
|
133 |
+
gr.Markdown("## Examples")
|
134 |
+
gr.Examples(
|
135 |
+
examples=[["examples/Bach_847.mid", "", 120, 0.95, 512, "0-4"],
|
136 |
+
["examples/Bach_847.mid", "Cm C7/E Fm F#dim G7", 120, 0.95, 512, "0-4"],
|
137 |
+
["examples/Boney_m_ma_baker.mid", "", 120, 0.95, 512, "0-4"],
|
138 |
+
["examples/Eminem_slim_shady.mid", "Cm AbM BbM G7 Cm", 120, 0.95, 512, "0-4"],
|
139 |
+
["examples/Mozart_alla_turca.mid", "", 120, 0.95, 512, "0-4"],
|
140 |
+
["examples/Mozart_alla_turca.mid", "Am Em CM G7 E7 Am Am E7 Am", 120, 0.95, 512, "0-4"],
|
141 |
+
["examples/Daft_punk_Around_the_world.mid", "", 120, 0.95, 512, "0-4"],
|
142 |
+
],
|
143 |
+
inputs=[midi_file, chord_progression, tempo, temperature, nb_tokens, bar_range],
|
144 |
+
outputs=[generated_music, generated_midi, info_message],
|
145 |
+
fn=musiclang,
|
146 |
+
cache_examples=True,
|
147 |
+
)
|
148 |
+
|
149 |
+
demo.launch()
|
flagged/log.csv
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
Number of Tokens,Temperature,Chord Progression,Tempo,Upload MIDI File,Bar Range,Generated Music,Download MIDI,Inferred output Chord Progression,Info Message,flag,username,timestamp
|
2 |
-
1024,0.9,,120,,0-4,"{""path"":""flagged/Generated Music/40e8a82a91668a20d35d/result.mp3"",""url"":""http://127.0.0.1:7860/file=/private/var/folders/52/q1zgqdvj1818brk2d_kw0stw0000gn/T/gradio/3926f3a3196bf0f0bbc8f54a4a464fa74a066dd9/result.mp3"",""size"":null,""orig_name"":""result.mp3"",""mime_type"":null,""is_stream"":false}","{""path"":""flagged/Download MIDI/1f6e813973ef7da5a542/test.mid"",""url"":""http://127.0.0.1:7860/file=/private/var/folders/52/q1zgqdvj1818brk2d_kw0stw0000gn/T/gradio/450e7e4a544b0fb7d114e7d3eadff382988e612b/test.mid"",""size"":2490,""orig_name"":""test.mid"",""mime_type"":null,""is_stream"":false}",Em CM Bm7b5/A Em GM Am Em/B Em GM Am Em/B Em GM Am Em/B Em GM Am Em/B Em GM Am Em/B Em Bm CM Em Em Bm CM Em GM Am Em/B Em GM Am Em/B Em GM Am Em/B,,,,2024-03-04 18:20:18.251715
|
|
|
|
|
|