Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import librosa
|
| 3 |
-
import soundfile as sf
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
import numpy as np
|
|
@@ -14,81 +13,83 @@ def ensure_directory_exists(directory):
|
|
| 14 |
os.makedirs(directory)
|
| 15 |
|
| 16 |
# Function to process the audio
|
| 17 |
-
def process_audio(file_path
|
| 18 |
# Ensure to navigate to the home directory first
|
| 19 |
os.chdir(home_directory)
|
| 20 |
|
| 21 |
file_name_without_ext = os.path.splitext(os.path.basename(file_path))[0]
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
os.
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
splitter.run()
|
| 32 |
-
st.write("Basic split process completed.")
|
| 33 |
-
os.chdir(home_directory)
|
| 34 |
-
ensure_directory_exists(os.path.join('vocal_remover', file_name_without_ext))
|
| 35 |
-
os.chdir('vocal_remover')
|
| 36 |
-
from moonarch_vocal_remover import VocalRemover
|
| 37 |
-
music_sep = VocalRemover(file_path)
|
| 38 |
-
music_sep.run()
|
| 39 |
-
st.write("Vocal remover process completed.")
|
| 40 |
-
os.chdir(home_directory)
|
| 41 |
-
return [
|
| 42 |
-
os.path.join('basic_splits', file_name_without_ext, 'vocals.wav'),
|
| 43 |
-
os.path.join('vocal_remover', file_name_without_ext, 'accompaniment.wav'),
|
| 44 |
-
os.path.join('basic_splits', file_name_without_ext, 'bass.wav'),
|
| 45 |
-
os.path.join('basic_splits', file_name_without_ext, 'drums.wav')
|
| 46 |
-
]
|
| 47 |
-
|
| 48 |
-
|
| 49 |
# Streamlit app
|
| 50 |
-
st.title('
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
if uploaded_file is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# Save uploaded file to a temporary location
|
| 58 |
audio_file_path = os.path.join(home_directory, f'{uploaded_file.name}')
|
| 59 |
with open(audio_file_path, 'wb') as f:
|
| 60 |
f.write(uploaded_file.getbuffer())
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
progress_bar
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
st.success('Audio processed successfully!')
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import librosa
|
|
|
|
| 3 |
import os
|
| 4 |
import time
|
| 5 |
import numpy as np
|
|
|
|
| 13 |
os.makedirs(directory)
|
| 14 |
|
| 15 |
# Function to process the audio
|
| 16 |
+
def process_audio(file_path):
|
| 17 |
# Ensure to navigate to the home directory first
|
| 18 |
os.chdir(home_directory)
|
| 19 |
|
| 20 |
file_name_without_ext = os.path.splitext(os.path.basename(file_path))[0]
|
| 21 |
+
output_dir = os.path.join('basic_splits', file_name_without_ext)
|
| 22 |
+
ensure_directory_exists(output_dir)
|
| 23 |
+
os.chdir('basic_splits')
|
| 24 |
|
| 25 |
+
from moonarch_basic import BasicSplitter
|
| 26 |
+
splitter = BasicSplitter(file_path)
|
| 27 |
+
splitter.run()
|
| 28 |
+
st.write("Basic split process completed.")
|
| 29 |
+
os.chdir(home_directory)
|
| 30 |
|
| 31 |
+
return [
|
| 32 |
+
os.path.join('basic_splits', file_name_without_ext, 'vocals.wav'),
|
| 33 |
+
os.path.join('basic_splits', file_name_without_ext, 'bass.wav'),
|
| 34 |
+
os.path.join('basic_splits', file_name_without_ext, 'drums.wav'),
|
| 35 |
+
os.path.join('basic_splits', file_name_without_ext, 'accompaniment.wav')
|
| 36 |
+
]
|
| 37 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Streamlit app
|
| 39 |
+
st.title('Moonarch Music Analysis')
|
| 40 |
+
st.header("Experience the Future of Sound")
|
| 41 |
+
st.write("""
|
| 42 |
+
Everything you need to create and release your music, including samples, plugins, unlimited distribution, and the world's best AI mastering engine.
|
| 43 |
+
""")
|
| 44 |
|
| 45 |
+
# Display the Start button
|
| 46 |
+
if st.button("Start using Moonarch"):
|
| 47 |
+
st.write("Welcome to Moonarch! Let's start creating amazing music.")
|
| 48 |
|
| 49 |
+
# Add upload option
|
| 50 |
+
uploaded_file = st.file_uploader("Upload a song", type=["mp3", "wav"])
|
| 51 |
|
| 52 |
if uploaded_file is not None:
|
| 53 |
+
st.write("File uploaded successfully.")
|
| 54 |
+
|
| 55 |
+
# Placeholder for progress bar
|
| 56 |
+
progress_bar = st.progress(0)
|
| 57 |
+
|
| 58 |
# Save uploaded file to a temporary location
|
| 59 |
audio_file_path = os.path.join(home_directory, f'{uploaded_file.name}')
|
| 60 |
with open(audio_file_path, 'wb') as f:
|
| 61 |
f.write(uploaded_file.getbuffer())
|
| 62 |
|
| 63 |
+
# Simulate file processing
|
| 64 |
+
for percent_complete in range(100):
|
| 65 |
+
time.sleep(0.01)
|
| 66 |
+
progress_bar.progress(percent_complete + 1)
|
| 67 |
+
|
| 68 |
+
st.write("File processing complete.")
|
| 69 |
+
|
| 70 |
+
if st.button('Basic Split'):
|
| 71 |
+
with st.spinner('Splitting audio...'):
|
| 72 |
+
output_files = process_audio(audio_file_path)
|
| 73 |
+
|
| 74 |
+
st.success('Audio processed successfully!')
|
|
|
|
| 75 |
|
| 76 |
+
# Display and download each generated audio
|
| 77 |
+
for file in output_files:
|
| 78 |
+
file_name = os.path.basename(file)
|
| 79 |
+
if 'vocals.wav' in file_name:
|
| 80 |
+
st.write('Vocal')
|
| 81 |
+
elif 'bass.wav' in file_name:
|
| 82 |
+
st.write('Bass')
|
| 83 |
+
elif 'drums.wav' in file_name:
|
| 84 |
+
st.write('Drums')
|
| 85 |
+
elif 'accompaniment.wav' in file_name:
|
| 86 |
+
st.write('Music')
|
| 87 |
+
|
| 88 |
+
st.audio(file)
|
| 89 |
+
with open(file, 'rb') as f:
|
| 90 |
+
st.download_button(
|
| 91 |
+
label=f'Download {file_name}',
|
| 92 |
+
data=f,
|
| 93 |
+
file_name=file_name,
|
| 94 |
+
mime='audio/wav'
|
| 95 |
+
)
|