floriangardin commited on
Commit
d8926bd
1 Parent(s): d3f08d7

add basic application

Browse files
Files changed (4) hide show
  1. .gitignore +3 -0
  2. app.py +42 -0
  3. packages.txt +2 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+
2
+ .idea/
3
+ *.mid
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from musiclang_predict import MusicLangPredictor # Assuming this is the correct import
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 = 16
12
+
13
+ # Initialize the MusicLangPredictor
14
+ ml = MusicLangPredictor('musiclang/musiclang-v2')
15
+ # Generate the score
16
+ score = ml.predict(nb_tokens=nb_tokens, temperature=temperature, topp=top_p, rng_seed=seed)
17
+
18
+ # Save the score as a MIDI file
19
+ midi_path = 'test.mid'
20
+ score.to_midi(midi_path)
21
+
22
+ # Convert MIDI to WAV then WAV to MP3
23
+ wav_path = 'result.wav'
24
+ mp3_path = 'result.mp3'
25
+ FluidSynth("/usr/share/sounds/sf2/FluidR3_GM.sf2").midi_to_audio(midi_path, wav_path)
26
+
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=None,
37
+ outputs=gr.Audio(label="Generated Music"),
38
+ title="Music Generation with MusicLang",
39
+ description="Click the button to generate music."
40
+ )
41
+
42
+ iface.launch()
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ffmpeg
2
+ fluidsynth
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ musiclang_predict==1.1.5
2
+ pyFluidSynth
3
+ midi2audio