Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import librosa
|
|
|
|
| 3 |
import os
|
| 4 |
import time
|
| 5 |
import numpy as np
|
|
@@ -13,97 +14,80 @@ def ensure_directory_exists(directory):
|
|
| 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 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
# Vocal Remover within Basic Split
|
| 33 |
-
ensure_directory_exists(os.path.join('basic_splits', 'vocal_remover', file_name_without_ext))
|
| 34 |
-
os.chdir(os.path.join('basic_splits', 'vocal_remover', file_name_without_ext))
|
| 35 |
-
from moonarch_vocal_remover import VocalRemover
|
| 36 |
-
music_sep = VocalRemover(file_path)
|
| 37 |
-
music_sep.run()
|
| 38 |
-
st.write("Vocal remover process completed.")
|
| 39 |
-
os.chdir(home_directory)
|
| 40 |
|
| 41 |
-
return [
|
| 42 |
-
os.path.join('basic_splits', file_name_without_ext, 'vocals.wav'),
|
| 43 |
-
os.path.join('basic_splits', '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 |
# Streamlit app
|
| 49 |
-
st.title('
|
| 50 |
-
st.header("Experience the Future of Sound")
|
| 51 |
-
st.write("""
|
| 52 |
-
Everything you need to create and release your music, including samples, plugins, unlimited distribution, and the world's best AI mastering engine.
|
| 53 |
-
""")
|
| 54 |
|
| 55 |
-
|
| 56 |
-
if st.button("Start using Moonarch"):
|
| 57 |
-
st.write("Welcome to Moonarch! Let's start creating amazing music.")
|
| 58 |
|
| 59 |
-
|
| 60 |
-
uploaded_file = st.file_uploader("Upload a song", type=["mp3", "wav"])
|
| 61 |
|
| 62 |
if uploaded_file is not None:
|
| 63 |
-
st.write("File uploaded successfully.")
|
| 64 |
-
|
| 65 |
-
# Placeholder for progress bar
|
| 66 |
-
progress_bar = st.progress(0)
|
| 67 |
-
|
| 68 |
# Save uploaded file to a temporary location
|
| 69 |
audio_file_path = os.path.join(home_directory, f'{uploaded_file.name}')
|
| 70 |
with open(audio_file_path, 'wb') as f:
|
| 71 |
f.write(uploaded_file.getbuffer())
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
progress_bar.progress(
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
mime='audio/wav'
|
| 106 |
-
)
|
| 107 |
-
else:
|
| 108 |
-
st.error(f"Error: {file} not found.")
|
| 109 |
-
st.write(f"Expected location: {file}")
|
|
|
|
| 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 |
os.makedirs(directory)
|
| 15 |
|
| 16 |
# Function to process the audio
|
| 17 |
+
def process_audio(file_path, choice):
|
| 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 |
+
if choice == 'Basic Split':
|
| 25 |
+
output_dir = os.path.join('basic_splits', file_name_without_ext)
|
| 26 |
+
ensure_directory_exists(output_dir)
|
| 27 |
+
os.chdir('basic_splits')
|
| 28 |
+
from moonarch_basic import BasicSplitter
|
| 29 |
+
splitter = BasicSplitter(file_path)
|
| 30 |
+
splitter.run()
|
| 31 |
+
st.write("Basic split process completed.")
|
| 32 |
+
os.chdir(home_directory)
|
| 33 |
+
ensure_directory_exists(os.path.join('vocal_remover', file_name_without_ext))
|
| 34 |
+
os.chdir('vocal_remover')
|
| 35 |
+
from moonarch_vocal_remover import VocalRemover
|
| 36 |
+
music_sep = VocalRemover(file_path)
|
| 37 |
+
music_sep.run()
|
| 38 |
+
st.write("Vocal remover process completed.")
|
| 39 |
+
os.chdir(home_directory)
|
| 40 |
+
return [
|
| 41 |
+
os.path.join('basic_splits', file_name_without_ext, 'vocals.wav'),
|
| 42 |
+
os.path.join('vocal_remover', file_name_without_ext, 'accompaniment.wav'),
|
| 43 |
+
os.path.join('basic_splits', file_name_without_ext, 'bass.wav'),
|
| 44 |
+
os.path.join('basic_splits', file_name_without_ext, 'drums.wav')
|
| 45 |
+
]
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
# Streamlit app
|
| 49 |
+
st.title('Monarch Music Analysis: Basic Splitter')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
task_choice = st.selectbox('Choose a task', ['Basic Split'])
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
uploaded_file = st.file_uploader('Upload an audio file', type=['mp3', 'wav'])
|
|
|
|
| 54 |
|
| 55 |
if uploaded_file is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
# Save uploaded file to a temporary location
|
| 57 |
audio_file_path = os.path.join(home_directory, f'{uploaded_file.name}')
|
| 58 |
with open(audio_file_path, 'wb') as f:
|
| 59 |
f.write(uploaded_file.getbuffer())
|
| 60 |
|
| 61 |
+
y, sr = librosa.load(audio_file_path, sr=None) # sr=None to use the native sample rate
|
| 62 |
+
|
| 63 |
+
if st.button('Start'):
|
| 64 |
+
progress_bar = st.progress(0)
|
| 65 |
+
|
| 66 |
+
# Simulate progress bar for processing
|
| 67 |
+
for percent_complete in range(100):
|
| 68 |
+
time.sleep(0.01)
|
| 69 |
+
progress_bar.progress(percent_complete + 1)
|
| 70 |
+
|
| 71 |
+
output_files = process_audio(audio_file_path, task_choice)
|
| 72 |
+
|
| 73 |
+
st.success('Audio processed successfully!')
|
| 74 |
|
| 75 |
+
for file in output_files:
|
| 76 |
+
file_name = os.path.basename(file)
|
| 77 |
+
if 'vocals.wav' in file:
|
| 78 |
+
st.write('Vocal')
|
| 79 |
+
elif 'accompaniment.wav' in file:
|
| 80 |
+
st.write('Music')
|
| 81 |
+
elif 'bass.wav' in file:
|
| 82 |
+
st.write('Bass')
|
| 83 |
+
elif 'drums.wav' in file:
|
| 84 |
+
st.write('Drums')
|
| 85 |
+
elif 'piano.wav' in file:
|
| 86 |
+
st.write('Piano')
|
| 87 |
+
elif 'strings_or_pads.wav' in file:
|
| 88 |
+
st.write('Strings or Pads')
|
| 89 |
+
|
| 90 |
+
st.audio(file)
|
| 91 |
+
with open(file, 'rb') as f:
|
| 92 |
+
new_file_name = 'music.wav' if file_name == 'accompaniment.wav' else ('strings_or_pads.wav' if file_name == 'other.wav' else file_name)
|
| 93 |
+
st.download_button(label=f'Download {new_file_name}', data=f, file_name=new_file_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|