Spaces:
Running
on
Zero
Running
on
Zero
mrfakename
commited on
Commit
•
528cc89
1
Parent(s):
d29645a
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,21 @@ from midi_util import VocabConfig
|
|
6 |
import tempfile
|
7 |
from glob import glob
|
8 |
import soundfile as sf
|
9 |
-
|
|
|
10 |
def gen(piano_only, length):
|
11 |
midi = ''
|
12 |
for item in musicgen(piano_only=piano_only, length=length):
|
13 |
midi = item
|
14 |
-
yield item, None
|
15 |
bio = BytesIO()
|
16 |
cfg = VocabConfig.from_json('./vocab_config.json')
|
17 |
text = midi.strip()
|
18 |
mid = midi_util.convert_str_to_midi(cfg, text)
|
19 |
-
with tempfile.NamedTemporaryFile(suffix='.midi', delete=False) as tmp:
|
20 |
mid.save(tmp.name)
|
21 |
-
|
|
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("# RWKV 4 Music (MIDI)\n\nThis demo uses the RWKV 4 MIDI model available [here](https://huggingface.co/BlinkDL/rwkv-4-music/blob/main/RWKV-4-MIDI-560M-v1-20230717-ctx4096.pth). Details may be found [here](https://huggingface.co/BlinkDL/rwkv-4-music). The music generation code may be found [here](https://github.com/BlinkDL/ChatRWKV/tree/main/music). The MIDI Tokenizer may be found [here](https://github.com/briansemrau/MIDI-LLM-tokenizer).\n\nNot sure how to play MIDI files? I recommend using the open source [VLC Media Player](https://www.videolan.org/vlc/) with can play MIDI files using FluidSynth.")
|
24 |
piano_only = gr.Checkbox(label="Piano Only")
|
@@ -26,7 +28,8 @@ with gr.Blocks() as demo:
|
|
26 |
synth = gr.Button("Synthesize")
|
27 |
txtout = gr.Textbox(interactive=False, label="MIDI Tokens")
|
28 |
fileout = gr.File(interactive=False, label="MIDI File", type="binary")
|
29 |
-
|
|
|
30 |
with gr.Accordion("Samples", open=False):
|
31 |
for i, audpath in enumerate(glob("*.wav")):
|
32 |
gr.Audio(interactive=False, value=sf.read(audpath), label=f'Sample {i + 1}')
|
|
|
6 |
import tempfile
|
7 |
from glob import glob
|
8 |
import soundfile as sf
|
9 |
+
from midi2audio import FluidSynth
|
10 |
+
fs = FluidSynth()
|
11 |
def gen(piano_only, length):
|
12 |
midi = ''
|
13 |
for item in musicgen(piano_only=piano_only, length=length):
|
14 |
midi = item
|
15 |
+
yield item, None, None
|
16 |
bio = BytesIO()
|
17 |
cfg = VocabConfig.from_json('./vocab_config.json')
|
18 |
text = midi.strip()
|
19 |
mid = midi_util.convert_str_to_midi(cfg, text)
|
20 |
+
with tempfile.NamedTemporaryFile(suffix='.midi', delete=False) as tmp, tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as aud:
|
21 |
mid.save(tmp.name)
|
22 |
+
fs.midi_to_audio(tmp.name, aud.name)
|
23 |
+
yield midi, tmp.name, aud.name
|
24 |
with gr.Blocks() as demo:
|
25 |
gr.Markdown("# RWKV 4 Music (MIDI)\n\nThis demo uses the RWKV 4 MIDI model available [here](https://huggingface.co/BlinkDL/rwkv-4-music/blob/main/RWKV-4-MIDI-560M-v1-20230717-ctx4096.pth). Details may be found [here](https://huggingface.co/BlinkDL/rwkv-4-music). The music generation code may be found [here](https://github.com/BlinkDL/ChatRWKV/tree/main/music). The MIDI Tokenizer may be found [here](https://github.com/briansemrau/MIDI-LLM-tokenizer).\n\nNot sure how to play MIDI files? I recommend using the open source [VLC Media Player](https://www.videolan.org/vlc/) with can play MIDI files using FluidSynth.")
|
26 |
piano_only = gr.Checkbox(label="Piano Only")
|
|
|
28 |
synth = gr.Button("Synthesize")
|
29 |
txtout = gr.Textbox(interactive=False, label="MIDI Tokens")
|
30 |
fileout = gr.File(interactive=False, label="MIDI File", type="binary")
|
31 |
+
audioout = gr.Audio(interactive=False, label="Audio")
|
32 |
+
synth.click(gen, inputs=[piano_only, length], outputs=[txtout, fileout, audioout])
|
33 |
with gr.Accordion("Samples", open=False):
|
34 |
for i, audpath in enumerate(glob("*.wav")):
|
35 |
gr.Audio(interactive=False, value=sf.read(audpath), label=f'Sample {i + 1}')
|