Create main_backup.py
Browse files- main_backup.py +99 -0
main_backup.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import librosa
|
| 3 |
+
import soundfile as sf
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
|
| 7 |
+
# Set the home directory path for moonarch
|
| 8 |
+
home_directory = os.getcwd()
|
| 9 |
+
|
| 10 |
+
# Function to ensure directory exists
|
| 11 |
+
def ensure_directory_exists(directory):
|
| 12 |
+
if not os.path.exists(directory):
|
| 13 |
+
os.makedirs(directory)
|
| 14 |
+
|
| 15 |
+
# Function to process the audio
|
| 16 |
+
def process_audio(file_path, choice):
|
| 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 |
+
if choice == 'Vocal Remove':
|
| 23 |
+
output_dir = os.path.join('vocal_remover', file_name_without_ext)
|
| 24 |
+
ensure_directory_exists(output_dir)
|
| 25 |
+
os.chdir('vocal_remover')
|
| 26 |
+
from moonarch_vocal_remover import VocalRemover
|
| 27 |
+
splitter = VocalRemover(file_path)
|
| 28 |
+
splitter.run()
|
| 29 |
+
os.chdir(home_directory)
|
| 30 |
+
return [os.path.join(output_dir, 'vocals.wav'), os.path.join(output_dir, 'accompaniment.wav')]
|
| 31 |
+
|
| 32 |
+
elif choice == 'Basic Split':
|
| 33 |
+
output_dir = os.path.join('basic_splits', file_name_without_ext)
|
| 34 |
+
ensure_directory_exists(output_dir)
|
| 35 |
+
os.chdir('basic_splits')
|
| 36 |
+
from moonarch_basic import BasicSplitter
|
| 37 |
+
splitter = BasicSplitter(file_path)
|
| 38 |
+
splitter.run()
|
| 39 |
+
os.chdir(home_directory)
|
| 40 |
+
ensure_directory_exists(os.path.join('vocal_remover', file_name_without_ext))
|
| 41 |
+
os.chdir('vocal_remover')
|
| 42 |
+
from moonarch_vocal_remover import VocalRemover
|
| 43 |
+
music_sep = VocalRemover(file_path)
|
| 44 |
+
music_sep.run()
|
| 45 |
+
os.chdir(home_directory)
|
| 46 |
+
return [
|
| 47 |
+
os.path.join('basic_splits', file_name_without_ext, 'vocals.wav'),
|
| 48 |
+
os.path.join('vocal_remover', file_name_without_ext, 'accompaniment.wav'),
|
| 49 |
+
os.path.join('basic_splits', file_name_without_ext, 'bass.wav'),
|
| 50 |
+
os.path.join('basic_splits', file_name_without_ext, 'drums.wav')
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
elif choice == 'Advanced Split':
|
| 54 |
+
output_dir = os.path.join('advance_splits', file_name_without_ext)
|
| 55 |
+
ensure_directory_exists(output_dir)
|
| 56 |
+
os.chdir('advance_splits')
|
| 57 |
+
from moonarch_advance import AdvanceSplitter
|
| 58 |
+
splitter = AdvanceSplitter(file_path)
|
| 59 |
+
splitter.run()
|
| 60 |
+
os.chdir(home_directory)
|
| 61 |
+
return [
|
| 62 |
+
os.path.join(output_dir, 'vocals.wav'),
|
| 63 |
+
os.path.join(output_dir, 'other.wav'),
|
| 64 |
+
os.path.join(output_dir, 'bass.wav'),
|
| 65 |
+
os.path.join(output_dir, 'drums.wav'),
|
| 66 |
+
os.path.join(output_dir, 'piano.wav')
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
# Streamlit app
|
| 70 |
+
st.title('Monarch Music Analysis')
|
| 71 |
+
|
| 72 |
+
task_choice = st.selectbox('Choose a task', ['Vocal Remove', 'Basic Split', 'Advanced Split'])
|
| 73 |
+
|
| 74 |
+
uploaded_file = st.file_uploader('Upload an audio file', type=['mp3', 'wav'])
|
| 75 |
+
|
| 76 |
+
if uploaded_file is not None:
|
| 77 |
+
# Save uploaded file to a temporary location
|
| 78 |
+
audio_file_path = os.path.join(home_directory, f'{uploaded_file.name}')
|
| 79 |
+
with open(audio_file_path, 'wb') as f:
|
| 80 |
+
f.write(uploaded_file.getbuffer())
|
| 81 |
+
|
| 82 |
+
y, sr = librosa.load(audio_file_path, sr=None) # sr=None to use the native sample rate
|
| 83 |
+
|
| 84 |
+
if st.button('Start'):
|
| 85 |
+
progress_bar = st.progress(0)
|
| 86 |
+
|
| 87 |
+
# Simulate progress bar for processing
|
| 88 |
+
for percent_complete in range(100):
|
| 89 |
+
time.sleep(0.01)
|
| 90 |
+
progress_bar.progress(percent_complete + 1)
|
| 91 |
+
|
| 92 |
+
output_files = process_audio(audio_file_path, task_choice)
|
| 93 |
+
|
| 94 |
+
st.success('Audio processed successfully!')
|
| 95 |
+
|
| 96 |
+
for file in output_files:
|
| 97 |
+
st.audio(file)
|
| 98 |
+
with open(file, 'rb') as f:
|
| 99 |
+
st.download_button(label=f'Download {os.path.basename(file)}', data=f, file_name=os.path.basename(file))
|