Gpagejr12 commited on
Commit
f880ab6
·
verified ·
1 Parent(s): 419d9bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -41
app.py CHANGED
@@ -32,11 +32,9 @@ def generate_music_tensors(descriptions, duration: int):
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 = "/content/drive/MyDrive/Colab Notebooks/audio_output"
39
- save_path= "audio_output/"
40
  assert samples.dim() == 2 or samples.dim() == 3
41
 
42
  samples = samples.detach().cpu()
@@ -55,13 +53,13 @@ def get_binary_file_downloader_html(bin_file, file_label='File'):
55
  return href
56
 
57
  st.set_page_config(
58
- page_icon= "musical_note",
59
- page_title= "Music Gen"
60
  )
61
 
62
  def main():
63
  with st.sidebar:
64
- st.header("""⚙️Generate Music ⚙️""",divider="rainbow")
65
  st.text("")
66
  st.subheader("1. Enter your music description.......")
67
  bpm = st.number_input("Enter Speed in BPM", min_value=60)
@@ -70,49 +68,42 @@ def main():
70
  st.text('')
71
  # Dropdown for genres
72
  selected_genre = st.selectbox("Select Genre", genres)
73
-
74
  st.subheader("2. Select time duration (In Seconds)")
75
  time_slider = st.slider("Select time duration (In Seconds)", 0, 60, 10)
76
 
77
  st.title("""🎵 Song Lab AI 🎵""")
78
  st.text('')
79
- left_co,right_co = st.columns(2)
80
  left_co.write("""Music Generation through a prompt""")
81
  left_co.write(("""PS : First generation may take some time ......."""))
82
 
83
-
84
- if st.sidebar.button('Generate !'):
85
- with left_co:
86
- st.text('')
87
- st.text('')
88
- st.text('')
89
- st.text('')
90
- st.text('')
91
- st.text('')
92
- st.subheader("Generated Music")
93
-
94
- # Generate audio
95
- descriptions = [f"{text_area} {selected_genre} {bpm} BPM" for _ in range(5)] # Adjust the batch size (5 in this case)
96
- music_tensors = generate_music_tensors(descriptions, time_slider)
97
-
98
- # Only play the full audio for index 0
99
- idx = 0
100
- music_tensor = music_tensors[idx]
101
- save_music_file = save_audio(music_tensor)
102
- # audio_filepath = f'/content/drive/MyDrive/Colab Notebooks/audio_output/audio_{idx}.wav'
103
- audio_filepath = 'audio_output/audio_0.wav'
104
- audio_file = open(audio_filepath, 'rb')
105
- audio_bytes = audio_file.read()
106
-
107
- # Play the full audio
108
- st.audio(audio_bytes, format='audio/wav')
109
- st.markdown(get_binary_file_downloader_html(audio_filepath, 'Audio'), unsafe_allow_html=True)
110
-
111
- save_path = "audio_output/"
112
- os.makedirs(save_path, exist_ok=True) # Create the directory if it doesn't exist
113
-
114
-
115
 
116
  if __name__ == "__main__":
117
  main()
118
-
 
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
  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 ⚙️""", divider="rainbow")
63
  st.text("")
64
  st.subheader("1. Enter your music description.......")
65
  bpm = st.number_input("Enter Speed in BPM", min_value=60)
 
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, right_co = st.columns(2)
78
  left_co.write("""Music Generation through a prompt""")
79
  left_co.write(("""PS : First generation may take some time ......."""))
80
 
81
+ if st.sidebar.button('Generate !'):
82
+ with left_co:
83
+ st.text('')
84
+ st.text('')
85
+ st.text('')
86
+ st.text('')
87
+ st.text('')
88
+ st.text('')
89
+ st.subheader("Generated Music")
90
+
91
+ # Generate audio
92
+ descriptions = [f"{text_area} {selected_genre} {bpm} BPM" for _ in range(5)] # Adjust the batch size (5 in this case)
93
+ music_tensors = generate_music_tensors(descriptions, time_slider)
94
+
95
+ # Only play the full audio for index 0
96
+ idx = 0
97
+ music_tensor = music_tensors[idx]
98
+ save_music_file = save_audio(music_tensor)
99
+ # audio_filepath = f'/content/drive/MyDrive/Colab Notebooks/audio_output/audio_{idx}.wav'
100
+ audio_filepath = 'audio_output/audio_0.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, 'Audio'), unsafe_allow_html=True)
 
 
 
 
 
 
107
 
108
  if __name__ == "__main__":
109
  main()