-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain_gui.py
181 lines (135 loc) · 12.1 KB
/
main_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import PySimpleGUI as sg
import os
from utility.gui import get_themed_icon
version = '0.8.1'
splash = sg.Window('Window Title', [[sg.Image(filename='utility/data/splash.png')]], transparent_color=sg.theme_background_color(), no_titlebar=True, keep_on_top=True)
splash.read(timeout=0)
from utility.gui import *
from utility.constants import *
from diffusion_library.sampler import SamplerType
from diffusion_library.scheduler import SchedulerType
sg.theme(load_theme()) # Add a touch of color
sg.set_options(font='Helvetica 10')
sg.set_options(suppress_raise_key_errors=False, suppress_error_popups=True, suppress_key_guessing=True)
from utility.elements import CustomFolderBrowse, CustomFileBrowse
disabled_modes = ["Inpainting", "Extension"]
modes = [x for x in RequestType._member_names_ if x not in disabled_modes]
tree_layout = [
[sg.Button('', key='Play', font='Helvetica 20', image_data=TOP_PLAY, button_color=sg.theme_background_color(), border_width=0), sg.Button('', key='Save', font='Helvetica 20', image_data=TOP_SAVE, button_color=sg.theme_background_color(), border_width=0), sg.Button('', key='Locate', font='Helvetica 20', image_data=TOP_FOLDER, button_color=sg.theme_background_color(), border_width=0), sg.Button('Load As Input'), sg.T('Preview Volume: '), sg.Slider(range=(0, 100), orientation='h', size=(50, 20), enable_events=True, key="-VOLUME-", default_value=100, disable_number_display=True)],
[sg.Tree(data=sg.TreeData(), key='file_tree', headings=[], auto_size_columns=True, enable_events=True, show_expanded=True, expand_x=True, expand_y=True, row_height=30)]
]
settings_main = sg.Column([
[sg.T('Model File', tooltip='Path to the model checkpoint file to be used.'), sg.Combo([], key='model', default_value='', enable_events=True, size=(30,0))],
[sg.T('Mode', tooltip='The mode of operation'), sg.Combo(modes, default_value=default_settings['mode'], key='mode')],
[sg.T('Output Path', tooltip='Path for output renders.'), sg.InputText('output', key='output_path'), CustomFolderBrowse()],
[sg.T('Batch Loop', tooltip='The number of times the internal batch size will loop.'), sg.InputText('1', key='batch_loop', size=(8,0), enable_events=True)],
[sg.T('Internal Batch Size', tooltip='The maximal number of samples to be produced per batch.'), sg.InputText(default_settings['batch_size'], key='batch_size', size=(15,0), enable_events=True), sg.T('Total output files: 1', tooltip='Batch Loop * Internal Batch Size', key='batch_viewer', text_color='yellow')],
[sg.T('Custom Batch Name', tooltip='Custom batch name for filenames.'), sg.InputText('', key='custom_batch_name', size=(15,0), enable_events=True)],
[sg.T('Sample Rate', tooltip=' The samplerate the model was trained on.'), sg.InputText(default_settings['sample_rate'], key='sample_rate', size=(8,0), enable_events=True)],
[sg.T('Chunk Size', tooltip='The native chunk size of the model.'), sg.InputText(default_settings['chunk_size'], key='chunk_size', size=(8,0), enable_events=True), sg.T('', key='total_seconds')],
[sg.T('Seed', tooltip='The seed used for reproducable outputs. -1 for random seed.'), sg.InputText(default_settings['seed'], key='seed', size=(8,0))],
[sg.T('Secondary Model File', tooltip='Secondary model file used for merging.'), sg.Combo([], key='secondary_model', default_value='None', enable_events=True, size=(30,0))],
[sg.T('Secondary Merge Ratio', tooltip='Merge ratio for model merging [A-B] -> [0-1]'), sg.InputText('0.5', key='merge_ratio', size=(5,0), enable_events=True)],
], scrollable=True, vertical_scroll_only=True, expand_x=True, expand_y=True)
settings_add = sg.Column([
[sg.T('Input Audio Path', key='ipathtext', tooltip='Path to audio (used for variations & interpolations).'), sg.Button('❌', key='clear_audio_source', button_color=sg.theme_background_color(), border_width=0), sg.InputText(default_settings['audio_source'], key='audio_source', disabled_readonly_background_color='DarkGrey'), CustomFileBrowse(file_types=(("Audio Files", ".wav .flac"),)), sg.Button('', image_data=get_themed_icon(DROP_ICON), key='drop_source', button_color=sg.theme_background_color(), border_width=0)],
[sg.T('Input Folder Path', key='fpathtext', tooltip='Path to folder containing audio (used for variations & interpolations).'), sg.Button('❌', key='clear_audio_source_folder', button_color=sg.theme_background_color(), border_width=0), sg.InputText(default_settings['audio_source_folder'], key='audio_source_folder', disabled_readonly_background_color='DarkGrey'), CustomFolderBrowse()],
[sg.T('Generate Wave Input', tooltip='Generate wave for input (used for variations & interpolations).'), sg.Combo(['Sine', 'Square', 'Saw', 'None'], default_value=default_settings['gen_wave'], key='gen_wave', enable_events=True)],
[sg.T('Generate Wave Keys', tooltip='Key schedule for the wave generation. (Separate by , !)'), sg.InputText(default_settings['gen_keys'], key='gen_keys'), sg.Button('', key='Preview Keys', image_data=get_themed_icon(TOP_PLAY), button_color=sg.theme_background_color(), border_width=0)],
[sg.T('Generate Wave Amplitude', tooltip='Amp for the generated wave.'), sg.InputText(default_settings['gen_amp'], key='gen_amp', size=(15,0))],
[sg.T('Interp Audio Target Path', tooltip='Path to the audio target (used for interpolations).'), sg.Button('❌', key='clear_audio_target', button_color=sg.theme_background_color(), border_width=0), sg.InputText(default_settings['audio_target'], key='audio_target'), CustomFileBrowse(file_types=(("Audio Files", ".wav .flac"),)), sg.Button('', image_data=get_themed_icon(DROP_ICON), key='drop_target', button_color=sg.theme_background_color(), border_width=0)],
[sg.T('Interp Steps', tooltip='The number of interpolations.'), sg.InputText(default_settings['interpolations_linear'], key='interpolations_linear', size=(5,0))],
[sg.Checkbox('Use Autocast', default=default_settings['use_autocast'], key='use_autocast', tooltip='Autocasting automatically chooses the precision for GPU operations to improve performance while maintaining accuracy.'), sg.T('Crop Offset'), sg.Input(tooltip='The starting sample offset to crop input audio to. Use -1 for random cropping.', key='crop_offset', default_text=default_settings['crop_offset'])],
[sg.Checkbox('Tame', default=default_settings['tame'], key='tame', tooltip='Decrease output by 3db, then clip.'), sg.Checkbox('Keep Start', default=default_settings['keep_start'], key='keep_start', tooltip='Keep beginning of audio provided(only applies to mode Extension).')],
[sg.T('Noise Level', tooltip='The noise level (used for variations & interpolations).'), sg.InputText(default_settings['noise_level'], key='noise_level', size=(15,0))],
], scrollable=True, vertical_scroll_only=True, expand_x=True, expand_y=True)
settings_sampler = sg.Column([
[sg.T('Steps', tooltip='The number of steps for the sampler.'), sg.InputText(default_settings['steps'], key='steps', size=(15,0))],
[sg.T('Sampler', tooltip='The sampler used for the diffusion model.'), sg.Combo(SamplerType._member_names_, default_value=default_settings['sampler'], key='sampler')],
[sg.T('Schedule', tooltip='The schedule used for the sampler.'), sg.Combo(SchedulerType._member_names_, default_value=default_settings['schedule'], key='schedule')],
[sg.T('DDIM-ETA'), sg.InputText('0', key='ddim_eta', size=(5,0))],
[sg.T('Resamples'), sg.InputText(default_settings['resamples'], key='resamples', size=(5,0), tooltip='Number of resampling steps in conventional samplers for inpainting.')],
#[sg.Checkbox('K-Alt Sigma Function', default=False, key='alt_sigma', enable_events=True)],
[sg.T('K-Sigma Min', key='smintext'), sg.InputText('0.01', key='sigma_min', size=(7,0), disabled_readonly_background_color='DarkGrey')],
[sg.T('K-Sigma Max', key='smaxtext'), sg.InputText('50', key='sigma_max', size=(7,0), disabled_readonly_background_color='DarkGrey')],
[sg.T('K-RHO'), sg.InputText('7', key='rho', size=(5,0))],
#[sg.T('K-adaptive-RTOL'), sg.InputText('0.01', key='rtol', size=(5,0))],
#[sg.T('K-adaptive-ATOL'), sg.InputText('0.01', key='atol', size=(5,0))],
], scrollable=True, vertical_scroll_only=True, expand_x=True, expand_y=True)
tabs = [sg.TabGroup([[sg.Tab('Main Settings', [[settings_main]], expand_y=False), sg.Tab('Additional Settings', [[settings_add]]), sg.Tab('Sampler Settings', [[settings_sampler]])]], expand_x=True, expand_y=True, key='tab_group')]
loading_gif_img = sg.Image(background_color=sg.theme_background_color(), key='-LOADINGGIF-')
buttons = [sg.Button('Generate'), loading_gif_img]
prog_bar = sg.ProgressBar(100, size=(0, 30), expand_x=True, key='prog_bar')
bottom_column = sg.Column([buttons, [prog_bar]], expand_x=True, expand_y=False)
window = sg.Window(f'Vextra Diffusion Toolkit v{version}', [
#[sg.Titlebar(title='', icon='util/data/dtico.png')],
[sg.Frame('Preview', tree_layout, expand_x=True, expand_y=True, size=(0,250))],
tabs,
[bottom_column],
[sg.Sizer(0, 10)],
], finalize=True, icon='utility/data/dtico2.ico', enable_close_attempted_event=True, resizable=True, size=(700,750), keep_on_top=get_config_value('stay_on_top'))
window.set_min_size((670,615))
splash.close()
window['file_tree'].bind('<Double-Button-1>', '_double_clicked')
window['-LOADINGGIF-'].update(visible=False)
def prog_callback(*args):
args = args[0]
prog_bar.update(current_count=args['value'], max=args['max'])
hijack_tqdm(prog_callback)
# init
exts = load_extensions(window)
load_settings(window)
refresh_models(window)
set_total_output(window)
set_total_seconds(window)
prog_bar.update_bar(100, 100)
if os.path.exists('./tmp'):
print('Removing tmp folder.')
shutil.rmtree('./tmp', ignore_errors=True)
curprog = 100
while True:
event, values = window.read(timeout=10)
loading_gif_img.update_animation(LOADING_GIF_B64, time_between_frames=50)
if event in (sg.WINDOW_CLOSE_ATTEMPTED_EVENT, 'Exit'):
save_settings(values)
break
if event.startswith('clear_'):
window[event.replace('clear_', '')].update(value='')
if event == 'drop_source':
result = show_drop_window(window, 'audio_source')
if event == 'drop_target':
result = show_drop_window(window, 'audio_target')
if event == 'Generate':
show_save_window(window, values)
if event == 'Import Model':
load_model(window)
if event == 'alt_sigma':
update_sigma(window, bool(values['alt_sigma']))
if event == 'gen_wave':
update_input_path(window, values['gen_wave'] != 'None')
if event == 'Preview Keys':
Thread(target=preview_keys, args=(window, values, )).start()
if event == 'model':
apply_model_params(window, values['model'])
if event in ('batch_loop', 'batch_size'):
set_total_output(window)
if event in ['sample_rate', 'model', 'chunk_size']:
set_total_seconds(window)
if event == '-VOLUME-':
set_volume(values['-VOLUME-'])
for ext in exts:
ext.handle_event_values(event, values)
if len(values['file_tree']) > 0:
if event in ('file_tree_double_clicked', 'Play'):
play_audio(values['file_tree'][0])
if event == 'Save':
Thread(target=copysave, args=(values, )).start()
if event == 'Locate':
open_in_finder(values['file_tree'][0])
if event == 'Load As Input':
try:
window['audio_source'].update(value=values['file_tree'][0])
window['mode'].update(value='Variation')
except (IndexError, TypeError):
pass
window.close()