Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -32,9 +32,10 @@ def generate_music_tensors(descriptions, duration: int):
|
|
32 |
st.success("Music Generation Complete!")
|
33 |
return output
|
34 |
|
|
|
35 |
def save_audio(samples: torch.Tensor):
|
36 |
sample_rate = 30000
|
37 |
-
save_path = "audio_output
|
38 |
assert samples.dim() == 2 or samples.dim() == 3
|
39 |
|
40 |
samples = samples.detach().cpu()
|
@@ -53,13 +54,13 @@ def get_binary_file_downloader_html(bin_file, file_label='File'):
|
|
53 |
return href
|
54 |
|
55 |
st.set_page_config(
|
56 |
-
page_icon="musical_note",
|
57 |
-
page_title="Music Gen"
|
58 |
)
|
59 |
|
60 |
def main():
|
61 |
with st.sidebar:
|
62 |
-
st.header("""⚙️Generate Music ⚙️""",
|
63 |
st.text("")
|
64 |
st.subheader("1. Enter your music description.......")
|
65 |
bpm = st.number_input("Enter Speed in BPM", min_value=60)
|
@@ -68,18 +69,17 @@ def main():
|
|
68 |
st.text('')
|
69 |
# Dropdown for genres
|
70 |
selected_genre = st.selectbox("Select Genre", genres)
|
71 |
-
|
72 |
st.subheader("2. Select time duration (In Seconds)")
|
73 |
time_slider = st.slider("Select time duration (In Seconds)", 0, 60, 10)
|
74 |
|
75 |
st.title("""🎵 Song Lab AI 🎵""")
|
76 |
st.text('')
|
77 |
-
left_co,
|
78 |
left_co.write("""Music Generation through a prompt""")
|
79 |
left_co.write(("""PS : First generation may take some time ......."""))
|
80 |
-
|
81 |
-
|
82 |
-
if st.button('Generate !'):
|
83 |
with left_co:
|
84 |
st.text('')
|
85 |
st.text('')
|
@@ -93,18 +93,18 @@ def main():
|
|
93 |
descriptions = [f"{text_area} {selected_genre} {bpm} BPM" for _ in range(5)] # Adjust the batch size (5 in this case)
|
94 |
music_tensors = generate_music_tensors(descriptions, time_slider)
|
95 |
|
96 |
-
|
97 |
idx = 0
|
98 |
music_tensor = music_tensors[idx]
|
99 |
save_music_file = save_audio(music_tensor)
|
100 |
-
|
101 |
-
audio_filepath = 'audio_output/audio_0.wav'
|
102 |
audio_file = open(audio_filepath, 'rb')
|
103 |
audio_bytes = audio_file.read()
|
104 |
|
105 |
# Play the full audio
|
106 |
st.audio(audio_bytes, format='audio/wav')
|
107 |
-
st.markdown(get_binary_file_downloader_html(audio_filepath, '
|
|
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
-
main()
|
|
|
32 |
st.success("Music Generation Complete!")
|
33 |
return output
|
34 |
|
35 |
+
|
36 |
def save_audio(samples: torch.Tensor):
|
37 |
sample_rate = 30000
|
38 |
+
save_path = "/audio_output"
|
39 |
assert samples.dim() == 2 or samples.dim() == 3
|
40 |
|
41 |
samples = samples.detach().cpu()
|
|
|
54 |
return href
|
55 |
|
56 |
st.set_page_config(
|
57 |
+
page_icon= "musical_note",
|
58 |
+
page_title= "Music Gen"
|
59 |
)
|
60 |
|
61 |
def main():
|
62 |
with st.sidebar:
|
63 |
+
st.header("""⚙️Generate Music ⚙️""",divider="rainbow")
|
64 |
st.text("")
|
65 |
st.subheader("1. Enter your music description.......")
|
66 |
bpm = st.number_input("Enter Speed in BPM", min_value=60)
|
|
|
69 |
st.text('')
|
70 |
# Dropdown for genres
|
71 |
selected_genre = st.selectbox("Select Genre", genres)
|
72 |
+
|
73 |
st.subheader("2. Select time duration (In Seconds)")
|
74 |
time_slider = st.slider("Select time duration (In Seconds)", 0, 60, 10)
|
75 |
|
76 |
st.title("""🎵 Song Lab AI 🎵""")
|
77 |
st.text('')
|
78 |
+
left_co,right_co = st.columns(2)
|
79 |
left_co.write("""Music Generation through a prompt""")
|
80 |
left_co.write(("""PS : First generation may take some time ......."""))
|
81 |
+
|
82 |
+
if st.sidebar.button('Generate !'):
|
|
|
83 |
with left_co:
|
84 |
st.text('')
|
85 |
st.text('')
|
|
|
93 |
descriptions = [f"{text_area} {selected_genre} {bpm} BPM" for _ in range(5)] # Adjust the batch size (5 in this case)
|
94 |
music_tensors = generate_music_tensors(descriptions, time_slider)
|
95 |
|
96 |
+
# Only play the full audio for index 0
|
97 |
idx = 0
|
98 |
music_tensor = music_tensors[idx]
|
99 |
save_music_file = save_audio(music_tensor)
|
100 |
+
audio_filepath = f'audio_output/audio_{idx}.wav'
|
|
|
101 |
audio_file = open(audio_filepath, 'rb')
|
102 |
audio_bytes = audio_file.read()
|
103 |
|
104 |
# Play the full audio
|
105 |
st.audio(audio_bytes, format='audio/wav')
|
106 |
+
st.markdown(get_binary_file_downloader_html(audio_filepath, f'Audio_{idx}'), unsafe_allow_html=True)
|
107 |
+
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
+
main()
|