Gpagejr12 commited on
Commit
b52703a
·
verified ·
1 Parent(s): ecc5750

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -13,16 +13,15 @@ def load_model():
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_seconds
23
  )
24
 
25
-
26
  with st.spinner("Generating Music..."):
27
  output = model.generate(
28
  descriptions=descriptions,
@@ -71,15 +70,13 @@ def main():
71
  # Dropdown for genres
72
  selected_genre = st.selectbox("Select Genre", genres)
73
 
74
- st.subheader("2. Select time duration (In Seconds)")
75
  # Adjust the time slider for selecting duration in minutes
76
  time_slider = st.slider("Select time duration (In Minutes)", 1, 5, 1)
77
 
78
- # Convert the selected minutes to seconds
79
  duration_seconds = time_slider * 60
80
 
81
- # time_slider = st.slider("Select time duration (In Seconds)", 0, 300, 10)
82
-
83
  st.title("""🎵 Song Lab AI 🎵""")
84
  st.text('')
85
  left_co,right_co = st.columns(2)
@@ -98,9 +95,9 @@ def main():
98
 
99
  # Generate audio
100
  descriptions = [f"{text_area} {selected_genre} {bpm} BPM" for _ in range(5)] # Adjust the batch size (5 in this case)
101
- music_tensors = generate_music_tensors(descriptions, time_slider)
102
 
103
- # Only play the full audio for index 0
104
  idx = 0
105
  music_tensor = music_tensors[idx]
106
  save_music_file = save_audio(music_tensor)
@@ -115,4 +112,3 @@ def main():
115
 
116
  if __name__ == "__main__":
117
  main()
118
-
 
13
  model = MusicGen.get_pretrained('facebook/musicgen-small')
14
  return model
15
 
16
+ def generate_music_tensors(descriptions, duration_seconds: int):
17
  model = load_model()
18
 
19
  model.set_generation_params(
20
+ use_sampling=True,
21
+ top_k=250,
22
+ duration=duration_seconds
23
  )
24
 
 
25
  with st.spinner("Generating Music..."):
26
  output = model.generate(
27
  descriptions=descriptions,
 
70
  # Dropdown for genres
71
  selected_genre = st.selectbox("Select Genre", genres)
72
 
73
+ st.subheader("2. Select time duration (In Minutes)")
74
  # Adjust the time slider for selecting duration in minutes
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('')
82
  left_co,right_co = st.columns(2)
 
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, duration_seconds)
99
 
100
+ # Only play the full audio for index 0
101
  idx = 0
102
  music_tensor = music_tensors[idx]
103
  save_music_file = save_audio(music_tensor)
 
112
 
113
  if __name__ == "__main__":
114
  main()