Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,13 +13,13 @@ def load_model():
|
|
13 |
model = MusicGen.get_pretrained('facebook/musicgen-small')
|
14 |
return model
|
15 |
|
16 |
-
def generate_music_tensors(descriptions,
|
17 |
model = load_model()
|
18 |
|
19 |
model.set_generation_params(
|
20 |
use_sampling=True,
|
21 |
-
top_k=
|
22 |
-
duration=
|
23 |
)
|
24 |
|
25 |
with st.spinner("Generating Music..."):
|
@@ -35,7 +35,7 @@ def generate_music_tensors(descriptions, duration_seconds: int):
|
|
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()
|
@@ -70,12 +70,8 @@ def main():
|
|
70 |
# Dropdown for genres
|
71 |
selected_genre = st.selectbox("Select Genre", genres)
|
72 |
|
73 |
-
st.subheader("2. Select time duration (In
|
74 |
-
|
75 |
-
time_slider = st.slider("Select time duration (In Minutes)", 1, 5, 1)
|
76 |
-
|
77 |
-
# Convert the selected minutes to seconds
|
78 |
-
duration_seconds = time_slider * 60
|
79 |
|
80 |
st.title("""🎵 Song Lab AI 🎵""")
|
81 |
st.text('')
|
@@ -95,13 +91,13 @@ def main():
|
|
95 |
|
96 |
# Generate audio
|
97 |
descriptions = [f"{text_area} {selected_genre} {bpm} BPM" for _ in range(5)] # Adjust the batch size (5 in this case)
|
98 |
-
music_tensors = generate_music_tensors(descriptions,
|
99 |
|
100 |
-
|
101 |
idx = 0
|
102 |
music_tensor = music_tensors[idx]
|
103 |
save_music_file = save_audio(music_tensor)
|
104 |
-
audio_filepath = f'audio_output/audio_{idx}.wav'
|
105 |
audio_file = open(audio_filepath, 'rb')
|
106 |
audio_bytes = audio_file.read()
|
107 |
|
@@ -112,3 +108,4 @@ def main():
|
|
112 |
|
113 |
if __name__ == "__main__":
|
114 |
main()
|
|
|
|
13 |
model = MusicGen.get_pretrained('facebook/musicgen-small')
|
14 |
return model
|
15 |
|
16 |
+
def generate_music_tensors(descriptions, duration: int):
|
17 |
model = load_model()
|
18 |
|
19 |
model.set_generation_params(
|
20 |
use_sampling=True,
|
21 |
+
top_k=250,
|
22 |
+
duration=duration
|
23 |
)
|
24 |
|
25 |
with st.spinner("Generating Music..."):
|
|
|
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()
|
|
|
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('')
|
|
|
91 |
|
92 |
# Generate audio
|
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 |
|
|
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
main()
|
111 |
+
|