Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,49 +9,6 @@ from midi2audio import FluidSynth
|
|
9 |
from streamlit_lottie import st_lottie
|
10 |
#import hydralit_components as hc
|
11 |
|
12 |
-
# Set page config
|
13 |
-
st.set_page_config(page_title="Music Generation", page_icon=":tada:", layout="wide")
|
14 |
-
|
15 |
-
def load_lottieurl(url):
|
16 |
-
r = requests.get(url)
|
17 |
-
if r.status_code != 200:
|
18 |
-
return None
|
19 |
-
return r.json()
|
20 |
-
|
21 |
-
# Load Lottie animation
|
22 |
-
#lottie_coding = load_lottieurl("https://assets5.lottiefiles.com/private_files/lf30_fjln45y5.json")
|
23 |
-
|
24 |
-
# Header section
|
25 |
-
with st.container():
|
26 |
-
left_column, right_column = st.columns(2)
|
27 |
-
with left_column:
|
28 |
-
st.subheader("Music Generation :musical_keyboard:")
|
29 |
-
st.write(
|
30 |
-
"Our website is an application of piano music generation, you can listen to new musical notes generated by LSTM artificial neural network, which is used in fields of AI and deep learning. Let's get it started :notes:"
|
31 |
-
)
|
32 |
-
with right_column:
|
33 |
-
# Display a GIF instead of Lottie animation
|
34 |
-
st.image("im.gif", use_column_width=True)
|
35 |
-
|
36 |
-
# Sidebar for user input
|
37 |
-
with st.sidebar:
|
38 |
-
len_notes = st.slider('Please Choose The Notes Length', 20, 750, 20, 4)
|
39 |
-
st.write("Notes Length = ", len_notes)
|
40 |
-
|
41 |
-
# Music generation functionality
|
42 |
-
if st.sidebar.button('Generate My Music'):
|
43 |
-
if len_notes:
|
44 |
-
with st.container():
|
45 |
-
st.write("---")
|
46 |
-
with st.spinner('✨ Your music is now under processing... ✨'):
|
47 |
-
time.sleep(10) # Simulate processing time
|
48 |
-
generate(10, len_notes)
|
49 |
-
|
50 |
-
fs = FluidSynth('font.sf2', sample_rate=44100)
|
51 |
-
fs.midi_to_audio('test_output2.mid', 'output.wav')
|
52 |
-
|
53 |
-
st.audio('output.wav')
|
54 |
-
st.markdown("Here you are! You can download your music by right-clicking on the media player.")
|
55 |
|
56 |
####################### Music Generation Functions #######################
|
57 |
def generate(seq_len, x):
|
@@ -84,6 +41,7 @@ def prepare_sequences(notes, pitchnames, n_vocab, seq_length):
|
|
84 |
|
85 |
return (network_input, normalized_input)
|
86 |
|
|
|
87 |
def create_network(network_input, n_vocab):
|
88 |
model = tf.keras.Sequential()
|
89 |
model.add(tf.keras.layers.LSTM(512, input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True, recurrent_dropout=0.3))
|
@@ -144,4 +102,44 @@ def create_midi(prediction_output):
|
|
144 |
offset += 0.5
|
145 |
|
146 |
midi_stream = stream.Stream(output_notes)
|
147 |
-
midi_stream.write('midi', fp='test_output2.mid')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
from streamlit_lottie import st_lottie
|
10 |
#import hydralit_components as hc
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
####################### Music Generation Functions #######################
|
14 |
def generate(seq_len, x):
|
|
|
41 |
|
42 |
return (network_input, normalized_input)
|
43 |
|
44 |
+
|
45 |
def create_network(network_input, n_vocab):
|
46 |
model = tf.keras.Sequential()
|
47 |
model.add(tf.keras.layers.LSTM(512, input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True, recurrent_dropout=0.3))
|
|
|
102 |
offset += 0.5
|
103 |
|
104 |
midi_stream = stream.Stream(output_notes)
|
105 |
+
midi_stream.write('midi', fp='test_output2.mid')
|
106 |
+
|
107 |
+
|
108 |
+
# Set page config
|
109 |
+
st.set_page_config(page_title="Music Generation", page_icon=":tada:", layout="wide")
|
110 |
+
|
111 |
+
|
112 |
+
# Header section
|
113 |
+
with st.container():
|
114 |
+
left_column, right_column = st.columns(2)
|
115 |
+
with left_column:
|
116 |
+
st.subheader("Music Generation :musical_keyboard:")
|
117 |
+
st.write(
|
118 |
+
"Our website is an application of piano music generation, you can listen to new musical notes generated by LSTM artificial neural network, which is used in fields of AI and deep learning. Let's get it started :notes:"
|
119 |
+
)
|
120 |
+
with right_column:
|
121 |
+
# Display a GIF instead of Lottie animation
|
122 |
+
st.image("im.gif", use_column_width=True)
|
123 |
+
|
124 |
+
# Sidebar for user input
|
125 |
+
with st.sidebar:
|
126 |
+
len_notes = st.slider('Please Choose The Notes Length', 20, 750, 20, 4)
|
127 |
+
st.write("Notes Length = ", len_notes)
|
128 |
+
|
129 |
+
# Music generation functionality
|
130 |
+
if st.sidebar.button('Generate My Music'):
|
131 |
+
if len_notes:
|
132 |
+
with st.container():
|
133 |
+
st.write("---")
|
134 |
+
with st.spinner('✨ Your music is now under processing... ✨'):
|
135 |
+
time.sleep(10) # Simulate processing time
|
136 |
+
generate(10, len_notes)
|
137 |
+
|
138 |
+
fs = FluidSynth('font.sf2', sample_rate=44100)
|
139 |
+
fs.midi_to_audio('test_output2.mid', 'output.wav')
|
140 |
+
|
141 |
+
st.audio('output.wav')
|
142 |
+
st.markdown("Here you are! You can download your music by right-clicking on the media player.")
|
143 |
+
|
144 |
+
|
145 |
+
|