Spaces:
Running
Running
floriangardin
commited on
Commit
•
cc611a7
1
Parent(s):
115df79
choose chord progression
Browse files
app.py
CHANGED
@@ -4,7 +4,9 @@ from musiclang import Score
|
|
4 |
from midi2audio import FluidSynth
|
5 |
import os
|
6 |
|
7 |
-
|
|
|
|
|
8 |
top_p = 1.0
|
9 |
seed = 0
|
10 |
|
@@ -59,9 +61,18 @@ def musiclang(nb_tokens, temperature, chord_progression, tempo, midi_file, bar_r
|
|
59 |
mp3_path = 'result.mp3'
|
60 |
FluidSynth("/usr/share/sounds/sf2/FluidR3_GM.sf2").midi_to_audio(midi_path, wav_path)
|
61 |
os.system(f'ffmpeg -i {wav_path} -acodec libmp3lame -y -loglevel quiet -stats {mp3_path}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
# Return the MP3 path for Gradio to display and the MIDI file path for download
|
64 |
-
return mp3_path, midi_path, chord_repr
|
65 |
|
66 |
# Update Gradio interface to include MIDI file upload and bar range selection
|
67 |
iface = gr.Interface(
|
@@ -77,12 +88,15 @@ iface = gr.Interface(
|
|
77 |
outputs=[
|
78 |
gr.Audio(label="Generated Music"),
|
79 |
gr.File(label="Download MIDI"),
|
80 |
-
gr.Textbox(label="Inferred output Chord Progression", lines=2, value="")
|
|
|
81 |
],
|
82 |
title="Controllable Symbolic Music Generation with MusicLang Predict",
|
83 |
-
description="""
|
|
|
|
|
84 |
\nChord qualities: M, m, 7, m7, m7b5, sus2, sus4, M7, dim, dim7. You can also specify the bass if it belongs to the chord (e.g., Bm/D).
|
85 |
-
|
86 |
)
|
87 |
|
88 |
iface.launch()
|
|
|
4 |
from midi2audio import FluidSynth
|
5 |
import os
|
6 |
|
7 |
+
|
8 |
+
|
9 |
+
def inner_loop(nb_tokens, temperature, chord_progression, tempo, midi_file, bar_range):
|
10 |
top_p = 1.0
|
11 |
seed = 0
|
12 |
|
|
|
61 |
mp3_path = 'result.mp3'
|
62 |
FluidSynth("/usr/share/sounds/sf2/FluidR3_GM.sf2").midi_to_audio(midi_path, wav_path)
|
63 |
os.system(f'ffmpeg -i {wav_path} -acodec libmp3lame -y -loglevel quiet -stats {mp3_path}')
|
64 |
+
return mp3_path, midi_path, chord_repr
|
65 |
+
|
66 |
+
def musiclang(nb_tokens, temperature, chord_progression, tempo, midi_file, bar_range):
|
67 |
+
exception = None
|
68 |
+
mp3_path, midi_path, chord_repr = None, None, None
|
69 |
+
try:
|
70 |
+
mp3_path, midi_path, chord_repr = inner_loop(nb_tokens, temperature, chord_progression, tempo, midi_file, bar_range)
|
71 |
+
except Exception as e:
|
72 |
+
exception = "Error : " + e.__class__.__name__ + " " + str(e)
|
73 |
|
74 |
# Return the MP3 path for Gradio to display and the MIDI file path for download
|
75 |
+
return mp3_path, midi_path, chord_repr, exception
|
76 |
|
77 |
# Update Gradio interface to include MIDI file upload and bar range selection
|
78 |
iface = gr.Interface(
|
|
|
88 |
outputs=[
|
89 |
gr.Audio(label="Generated Music"),
|
90 |
gr.File(label="Download MIDI"),
|
91 |
+
gr.Textbox(label="Inferred output Chord Progression", lines=2, value=""),
|
92 |
+
gr.Textbox(label="Info Message") # Initially hidden, shown only if there's an error
|
93 |
],
|
94 |
title="Controllable Symbolic Music Generation with MusicLang Predict",
|
95 |
+
description="""
|
96 |
+
\n Simple application that wraps <a href="https://github.com/musiclang/musiclang_predict">musiclang predict</a>.
|
97 |
+
\n Customize the music generation by specifying the number of tokens, temperature, chord progression, tempo, and optionally uploading a MIDI file to use as a prompt. Specify the bar range for the MIDI prompt.
|
98 |
\nChord qualities: M, m, 7, m7, m7b5, sus2, sus4, M7, dim, dim7. You can also specify the bass if it belongs to the chord (e.g., Bm/D).
|
99 |
+
If no chord progression or MIDI file is given, it generates a free sample with the specified number of tokens."""
|
100 |
)
|
101 |
|
102 |
iface.launch()
|