Add files via upload

This commit is contained in:
Anjok07 2022-04-15 04:03:19 -05:00 committed by GitHub
parent 159e14463d
commit a6fef6c6e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 100 deletions

View File

@ -41,6 +41,7 @@ if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(base_path) # Change the current working directory to the base path
instrumentalModels_dir = os.path.join(base_path, 'models')
@ -64,7 +65,6 @@ DEFAULT_DATA = {
'lastDir': None,
}
def open_image(path: str, size: tuple = None, keep_aspect: bool = True, rotate: int = 0) -> ImageTk.PhotoImage:
"""
Open the image on the path and apply given settings\n
@ -94,7 +94,6 @@ def open_image(path: str, size: tuple = None, keep_aspect: bool = True, rotate:
img = img.resize(size, Image.ANTIALIAS)
return ImageTk.PhotoImage(img)
def save_data(data):
"""
Saves given data as a .pkl (pickle) file
@ -107,7 +106,6 @@ def save_data(data):
with open('data.pkl', 'wb') as data_file:
pickle.dump(data, data_file)
def load_data() -> dict:
"""
Loads saved pkl file and returns the stored data
@ -126,7 +124,6 @@ def load_data() -> dict:
return load_data()
def drop(event, accept_mode: str = 'files'):
"""
Drag & Drop verification process
@ -153,12 +150,10 @@ def drop(event, accept_mode: str = 'files'):
# Invalid accept mode
return
class ThreadSafeConsole(tk.Text):
"""
Text Widget which is thread safe for tkinter
"""
def __init__(self, master, **options):
tk.Text.__init__(self, master, **options)
self.queue = queue.Queue()
@ -186,7 +181,6 @@ class ThreadSafeConsole(tk.Text):
self.configure(state=tk.DISABLED)
self.after(100, self.update_me)
class MainWindow(TkinterDnD.Tk):
# --Constants--
# Layout
@ -248,9 +242,10 @@ class MainWindow(TkinterDnD.Tk):
# Constants
self.winSize_var = tk.StringVar(value=data['window_size'])
self.agg_var = tk.StringVar(value=data['agg'])
# AI model
# Choose Conversion Method
self.aiModel_var = tk.StringVar(value=data['aiModel'])
self.last_aiModel = self.aiModel_var.get()
# Choose Ensemble
self.ensChoose_var = tk.StringVar(value=data['ensChoose'])
self.last_ensChoose = self.ensChoose_var.get()
# Other
@ -264,7 +259,6 @@ class MainWindow(TkinterDnD.Tk):
self.configure_widgets()
self.bind_widgets()
self.place_widgets()
self.update_available_models()
self.update_states()
self.update_loop()
@ -403,6 +397,22 @@ class MainWindow(TkinterDnD.Tk):
variable=self.modelFolder_var,
)
# -Column 2-
# Choose Conversion Method
self.options_aiModel_Label = tk.Label(master=self.options_Frame,
text='Choose Conversion Method', anchor=tk.CENTER,
background='#404040', font=self.font, foreground='white', relief="groove")
self.options_aiModel_Optionmenu = ttk.OptionMenu(self.options_Frame,
self.aiModel_var,
None, 'Single Model', 'Ensemble Mode')
# Ensemble Mode
self.options_ensChoose_Label = tk.Label(master=self.options_Frame,
text='Choose Ensemble', anchor=tk.CENTER,
background='#404040', font=self.font, foreground='white', relief="groove")
self.options_ensChoose_Optionmenu = ttk.OptionMenu(self.options_Frame,
self.ensChoose_var,
None, 'HP1 Models', 'HP2 Models', 'All HP Models', 'Vocal Models')
# -Column 3-
# WINDOW SIZE
self.options_winSize_Label = tk.Label(master=self.options_Frame,
@ -418,23 +428,6 @@ class MainWindow(TkinterDnD.Tk):
self.options_agg_Label = tk.Label(master=self.options_Frame,
text='Aggression Setting',
background='#404040', font=self.font, foreground='white', relief="groove")
# AI model
self.options_aiModel_Label = tk.Label(master=self.options_Frame,
text='Choose Conversion Method', anchor=tk.CENTER,
background='#404040', font=self.font, foreground='white', relief="groove")
self.options_aiModel_Optionmenu = ttk.OptionMenu(self.options_Frame,
self.aiModel_var,
None, 'Single Model', 'Ensemble Mode')
# Ensemble Mode
self.options_ensChoose_Label = tk.Label(master=self.options_Frame,
text='Choose Ensemble', anchor=tk.CENTER,
background='#404040', font=self.font, foreground='white', relief="groove")
self.options_ensChoose_Optionmenu = ttk.OptionMenu(self.options_Frame,
self.ensChoose_var,
None, 'HP1 Models', 'HP2 Models', 'All HP Models', 'Vocal Models')
# "Save to", "Select Your Audio File(s)"", and "Start Conversion" Button Style
s = ttk.Style()
@ -448,12 +441,8 @@ class MainWindow(TkinterDnD.Tk):
self.options_instrumentalModel_Optionmenu = ttk.OptionMenu(self.options_Frame,
self.instrumentalModel_var)
# Add Open Export Directory Button
# self.options_export_Button = ttk.Button(master=self.options_Frame,
# text='Open Export Directory',
# style="Bold.TButton",
# command=self.open_newModel_filedialog)
# -Place Widgets-
# -Column 1-
self.options_gpu_Checkbutton.place(x=0, y=0, width=0, height=0,
relx=0, rely=0, relwidth=1/3, relheight=1/self.COL1_ROWS)
@ -469,8 +458,6 @@ class MainWindow(TkinterDnD.Tk):
relx=0, rely=4/self.COL1_ROWS, relwidth=1/3, relheight=1/self.COL1_ROWS)
# -Column 2-
self.options_instrumentalModel_Label.place(x=-15, y=6, width=0, height=-10,
relx=1/3, rely=2/self.COL2_ROWS, relwidth=1/3, relheight=1/self.COL2_ROWS)
self.options_instrumentalModel_Optionmenu.place(x=-15, y=6, width=0, height=-10,
@ -481,14 +468,15 @@ class MainWindow(TkinterDnD.Tk):
relx=1/3, rely=0/self.COL2_ROWS, relwidth=1/3, relheight=1/self.COL2_ROWS)
self.options_ensChoose_Optionmenu.place(x=-15, y=6, width=0, height=-10,
relx=1/3, rely=1/self.COL2_ROWS, relwidth=1/3, relheight=1/self.COL2_ROWS)
# self.options_export_Button.place(x=0, y=0, width=-30, height=-8,
# relx=2/3, rely=4/self.COL3_ROWS, relwidth=1/3, relheight=1/self.COL3_ROWS)
# Conversion Method
self.options_aiModel_Label.place(x=-15, y=6, width=0, height=-10,
relx=1/3, rely=0/self.COL2_ROWS, relwidth=1/3, relheight=1/self.COL2_ROWS)
self.options_aiModel_Optionmenu.place(x=-15, y=4, width=0, height=-10,
relx=1/3, rely=1/self.COL2_ROWS, relwidth=1/3, relheight=1/self.COL2_ROWS)
# -Column 3-
# WINDOW
self.options_winSize_Label.place(x=35, y=6, width=-40, height=-10,
relx=2/3, rely=0, relwidth=1/3, relheight=1/self.COL3_ROWS)
@ -501,15 +489,6 @@ class MainWindow(TkinterDnD.Tk):
self.options_agg_Entry.place(x=80, y=6, width=-133, height=-10,
relx=2/3, rely=3/self.COL3_ROWS, relwidth=1/3, relheight=1/self.COL3_ROWS)
# Conversion Method
self.options_aiModel_Label.place(x=-15, y=6, width=0, height=-10,
relx=1/3, rely=0/self.COL2_ROWS, relwidth=1/3, relheight=1/self.COL2_ROWS)
self.options_aiModel_Optionmenu.place(x=-15, y=4, width=0, height=-10,
relx=1/3, rely=1/self.COL2_ROWS, relwidth=1/3, relheight=1/self.COL2_ROWS)
# Model deselect
self.aiModel_var.trace_add('write',
lambda *args: self.deselect_models())
@ -640,7 +619,6 @@ class MainWindow(TkinterDnD.Tk):
).start()
# Models
def update_inputPaths(self):
"""Update the music file entry"""
if self.inputPaths:
@ -665,7 +643,7 @@ class MainWindow(TkinterDnD.Tk):
#temp_instrumentalModels_dir = os.path.join(instrumentalModels_dir, self.aiModel_var.get(), 'Main Models') # nopep8
temp_instrumentalModels_dir = os.path.join(instrumentalModels_dir, 'Main Models') # nopep8
# Instrumental models
# Main models
new_InstrumentalModels = os.listdir(temp_instrumentalModels_dir)
if new_InstrumentalModels != self.lastInstrumentalModels:
self.instrumentalLabel_to_path.clear()
@ -679,13 +657,11 @@ class MainWindow(TkinterDnD.Tk):
self.instrumentalLabel_to_path[file_name] = os.path.join(temp_instrumentalModels_dir, file_name) # nopep8
self.lastInstrumentalModels = new_InstrumentalModels
def update_states(self):
"""
Vary the states for all widgets based
on certain selections
"""
if self.aiModel_var.get() == 'Single Model':
self.options_ensChoose_Label.place_forget()
self.options_ensChoose_Optionmenu.place_forget()
@ -804,7 +780,6 @@ class MainWindow(TkinterDnD.Tk):
self.destroy()
if __name__ == "__main__":
root = MainWindow()

View File

@ -32,7 +32,6 @@ class VocalRemover(object):
self.devices = defaultdict(lambda: None)
# self.offset = model.offset
data = {
# Paths
'input_paths': None,
@ -61,14 +60,12 @@ def update_progress(progress_var, total_files, file_num, step: float = 1):
progress_var.set(progress)
def get_baseText(total_files, file_num):
"""Create the base text for the command widget"""
text = 'File {file_num}/{total_files} '.format(file_num=file_num,
total_files=total_files)
return text
def determineModelFolderName():
"""
Determine the name that is used for the folder and appended
@ -109,8 +106,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
p.add_argument('--nn_architecture', type=str, choices= ['auto'] + list('{}KB'.format(s) for s in nn_arch_sizes), default='auto')
p.add_argument('--high_end_process', type=str, default='mirroring')
args = p.parse_args()
def save_files(wav_instrument, wav_vocals):
"""Save output music files"""
vocal_name = '(Vocals)'
@ -133,6 +129,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
wav_instrument, mp.param['sr'])
appendModelFolderName = modelFolderName.replace('/', '_')
# -Save files-
# Instrumental
if instrumental_name is not None:
@ -173,7 +170,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
os.mkdir(folder_path)
# Separation Preperation
try: #Load File(s)
try: #Load File(s)
for file_num, music_file in enumerate(data['input_paths'], start=1):
# Determine File Name
base_name = f'{data["export_path"]}{modelFolderName}/{file_num}_{os.path.splitext(os.path.basename(music_file))[0]}'
@ -190,8 +187,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
update_progress(**progress_kwargs,
step=0)
#Load Model(s)
#Load Model
text_widget.write(base_text + 'Loading models...')
@ -354,10 +350,8 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
else:
return pred * coef, X_mag, np.exp(1.j * X_phase)
aggressiveness = {'value': args.aggressiveness, 'split_bin': mp.param['band'][1]['crop_stop']}
if data['tta']:
text_widget.write(base_text + "Running Inferences (TTA)...\n")
else:
@ -402,6 +396,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
update_progress(**progress_kwargs,
step=1)
# Save output music files
text_widget.write(base_text + 'Saving Files...')
save_files(wav_instrument, wav_vocals)

View File

@ -28,7 +28,6 @@ class VocalRemover(object):
self.data = data
self.text_widget = text_widget
# self.offset = model.offset
data = {
# Paths
@ -60,7 +59,6 @@ def update_progress(progress_var, total_files, file_num, step: float = 1):
progress_var.set(progress)
def get_baseText(total_files, file_num):
"""Create the base text for the command widget"""
text = 'File {file_num}/{total_files} '.format(file_num=file_num,
@ -77,7 +75,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
31191, # default
33966, 123821, 123812, 537238 # custom
]
p = argparse.ArgumentParser()
p.add_argument('--aggressiveness',type=float, default=data['agg']/100)
@ -139,9 +136,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
button_widget.configure(state=tk.DISABLED) # Disable Button
# Separation Preperation
try: #Load File(s)
try: #Ensemble Dictionary
HP1_Models = [
{
'model_name':'HP_4BAND_44100_A',
@ -166,7 +161,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
'model_location':'models/Main Models/HP2_4BAND_44100_1.pth',
'using_archtecture': '537238KB',
'loop_name': 'Ensemble Mode - Model 1/3'
},
{
'model_name':'HP2_4BAND_44100_2',
@ -174,7 +168,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
'model_location':'models/Main Models/HP2_4BAND_44100_2.pth',
'using_archtecture': '537238KB',
'loop_name': 'Ensemble Mode - Model 2/3'
},
{
'model_name':'HP2_3BAND_44100_MSB2',
@ -225,7 +218,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
}
]
Vocal_Models = [
{
'model_name':'HP_Vocal_4BAND_44100',
@ -260,11 +252,8 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
ensefolder = 'Vocal_Models_Saved_Outputs'
ensemode = 'Vocal_Models'
#Prepare Audiofile(s)
for file_num, music_file in enumerate(data['input_paths'], start=1):
# -Get text and update progress-
base_text = get_baseText(total_files=len(data['input_paths']),
file_num=file_num)
@ -274,10 +263,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
update_progress(**progress_kwargs,
step=0)
#Load Model(s)
#text_widget.write(base_text + 'Loading models...')
#Prepare to loop models
for i, c in tqdm(enumerate(loops), disable=True, desc='Iterations..'):
text_widget.write(c['loop_name'] + '\n\n')
@ -300,7 +286,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
"""
enseFolderName = ''
# -Instrumental-
if str(ensefolder):
enseFolderName += os.path.splitext(os.path.basename(ensefolder))[0]
@ -326,7 +311,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
mp = ModelParameters(c['model_params'])
# -Instrumental-
#Load model
if os.path.isfile(c['model_location']):
device = torch.device('cpu')
model = nets.CascadedASPPNet(mp.param['bins'] * 2)
@ -340,7 +325,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
model_name = os.path.basename(c["model_name"])
# -Go through the different steps of seperation-
# Wave source
text_widget.write(base_text + 'Loading wave source... ')
@ -376,9 +360,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
step=0.1)
text_widget.write(base_text + 'Stft of wave source... ')
text_widget.write('Done!\n')
text_widget.write(base_text + "Please Wait...\n")
X_spec_m = spec_utils.combine_spectrograms(X_spec_s, mp)
@ -458,7 +440,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
aggressiveness = {'value': args.aggressiveness, 'split_bin': mp.param['band'][1]['crop_stop']}
if data['tta']:
text_widget.write(base_text + "Running Inferences (TTA)... \n")
else:
@ -468,10 +449,9 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
device,
model, aggressiveness)
update_progress(**progress_kwargs,
step=0.85)
# Postprocess
if data['postprocess']:
text_widget.write(base_text + 'Post processing... ')
@ -489,7 +469,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
if args.high_end_process.startswith('mirroring'):
input_high_end_ = spec_utils.mirroring(args.high_end_process, y_spec_m, input_high_end, mp)
wav_instrument = spec_utils.cmb_spectrogram_to_wave(y_spec_m, mp, input_high_end_h, input_high_end_)
else:
wav_instrument = spec_utils.cmb_spectrogram_to_wave(y_spec_m, mp)
@ -505,13 +484,12 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
update_progress(**progress_kwargs,
step=0.9)
# Save output music files
text_widget.write(base_text + 'Saving Files... ')
save_files(wav_instrument, wav_vocals)
text_widget.write('Done!\n')
# Save output image
if data['output_image']:
with open('{}_Instruments.jpg'.format(base_name), mode='wb') as f:
@ -526,7 +504,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
text_widget.write(base_text + 'Completed Seperation!\n\n')
# Emsembling Outputs
def get_files(folder="", prefix="", suffix=""):
return [f"{folder}{i}" for i in os.listdir(folder) if i.startswith(prefix) if i.endswith(suffix)]
@ -535,14 +512,14 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
'algorithm':'min_mag',
'model_params':'lib_v5/modelparams/1band_sr44100_hl512.json',
'files':get_files(folder=enseExport, prefix=trackname, suffix="_(Instrumental).wav"),
'output':'{}_Ensembled_{}_Instrumentals'.format(trackname, ensemode),
'output':'{}_Ensembled_{}_(Instrumental)'.format(trackname, ensemode),
'type': 'Instrumentals'
},
{
'algorithm':'max_mag',
'model_params':'lib_v5/modelparams/1band_sr44100_hl512.json',
'files':get_files(folder=enseExport, prefix=trackname, suffix="_(Vocals).wav"),
'output': '{}_Ensembled_{}_Vocals'.format(trackname, ensemode),
'output': '{}_Ensembled_{}_(Vocals)'.format(trackname, ensemode),
'type': 'Vocals'
}
]
@ -587,7 +564,6 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
text_widget.write("Done!\n")
update_progress(**progress_kwargs,
step=0.95)
text_widget.write("\n")
@ -602,12 +578,11 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
print(type(e).__name__, e)
print(message)
progress_var.set(0)
button_widget.configure(state=tk.NORMAL) # Enable Button
button_widget.configure(state=tk.NORMAL) #Enable Button
return
if len(os.listdir(enseExport)) == 0: # Check if the folder is empty
shutil.rmtree(folder_path)
if len(os.listdir(enseExport)) == 0: #Check if the folder is empty
shutil.rmtree(folder_path) #Delete folder if empty
update_progress(**progress_kwargs,
step=1)
@ -620,4 +595,4 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
text_widget.write(f'Conversions Completed!\n')
text_widget.write(f'Time Elapsed: {time.strftime("%H:%M:%S", time.gmtime(int(time.perf_counter() - stime)))}') # nopep8
torch.cuda.empty_cache()
button_widget.configure(state=tk.NORMAL) # Enable Button
button_widget.configure(state=tk.NORMAL) #Enable Button