Jaman commited on
Commit
a3c41f8
·
verified ·
1 Parent(s): c7b0fdf

Create backup_30_dec.py

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