mrfakename commited on
Commit
f6a823f
·
verified ·
1 Parent(s): 8150031

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -13
app.py CHANGED
@@ -9,18 +9,7 @@ from glob import glob
9
  import librosa
10
  from midi2audio import FluidSynth
11
  fs = FluidSynth()
12
- def trim_silence(filename, threshold=0.1, duration=0.5):
13
- y, sr = librosa.load(filename, sr=None)
14
- silent_frames = librosa.effects.split(y, top_db=threshold)
15
- total_duration = librosa.get_duration(y=y, sr=sr)
16
- duration_samples = int(duration * sr)
17
- trimmed_audio = []
18
- for start, end in silent_frames:
19
- if end - start > duration_samples:
20
- trimmed_audio.extend(y[start:end])
21
- trimmed_audio = np.array(trimmed_audio)
22
- librosa.output.write_wav(filename, y, sr=sr)
23
- return trimmed_audio, sr
24
  def gen(piano_only, length):
25
  midi = ''
26
  for item in musicgen(piano_only=piano_only, length=length):
@@ -33,7 +22,6 @@ def gen(piano_only, length):
33
  with tempfile.NamedTemporaryFile(suffix='.midi', delete=False) as tmp, tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as aud:
34
  mid.save(tmp.name)
35
  fs.midi_to_audio(tmp.name, aud.name)
36
- trim_silence(aud.name)
37
  yield midi, tmp.name, aud.name
38
  with gr.Blocks() as demo:
39
  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.")
 
9
  import librosa
10
  from midi2audio import FluidSynth
11
  fs = FluidSynth()
12
+
 
 
 
 
 
 
 
 
 
 
 
13
  def gen(piano_only, length):
14
  midi = ''
15
  for item in musicgen(piano_only=piano_only, length=length):
 
22
  with tempfile.NamedTemporaryFile(suffix='.midi', delete=False) as tmp, tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as aud:
23
  mid.save(tmp.name)
24
  fs.midi_to_audio(tmp.name, aud.name)
 
25
  yield midi, tmp.name, aud.name
26
  with gr.Blocks() as demo:
27
  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.")