Repository navigation
Expand file tree
/
Copy pathwebapp.py
More file actions
306 lines (284 loc) · 7.22 KB
/
Copy pathwebapp.py
File metadata and controls
306 lines (284 loc) · 7.22 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
### ###
### No Generative AI was used in the writing of this code. ###
### ###
import sys
import os
import gradio as gr
from pathlib import Path
from ezlocalizr import ezlocalizr
root_dir = Path(__file__).parent.parent.resolve()
os.environ['PYTHONPATH'] = str(root_dir)
sys.path.insert(0, str(root_dir))
from UTACompiler import utacompiler
from utils.logger_utils import get_logger
logger = get_logger(level="INFO")
webapp_src = Path('src')
assert webapp_src.exists()
if sys.platform in ['linux', 'linux2', 'darwin']:
sys_lang = os.environ['LANG']
elif sys.platform == 'win32':
import ctypes
import locale
windll = ctypes.windll.kernel32
sys_lang = locale.windows_locale[windll.GetUserDefaultUILanguage()]
else:
sys_lang = 'en_US' # fallback
L = ezlocalizr(
language=sys_lang,
string_path=webapp_src/'strings',
default_lang='en_US'
)
def dummy() -> None:
logger.info('bark bark :3')
def run_tool(
db_path: str,
db_name: str,
seed: int,
recording_style: str,
keep_files: str,
keep_folders: str,
pitches: str,
encoding: str,
scramble: bool,
glob_amt: int,
encoder_active: bool,
min_frq: int,
max_frq: int,
min_dur: float,
max_dur: float,
min_vol: float,
max_vol: float,
pad_val: float,
optimize: bool,
export_uar: bool,
) -> None:
config = {}
config['name'] = db_name
config['seed'] = seed
config['files'] = {}
try:
config['files']['keep_files'] = [x.strip() for x in keep_files.split(',')]
config['files']['keep_folders'] = [x.strip() for x in keep_folders.split(',')]
config['files']['pitches'] = [x.strip() for x in pitches.split(',')]
except Exception as e:
logger.error(f'Unable to process configuration: {e}')
sys.exit(1)
config['files']['file_encoding'] = encoding
config['files']['scramble'] = scramble
config['files']['glob'] = glob_amt
config['encoding'] = {}
config['encoding']['enabled'] = encoder_active
config['encoding']['min_frq'] = min_frq
config['encoding']['max_frq'] = max_frq
config['encoding']['min_dur'] = min_dur
config['encoding']['max_dur'] = max_dur
config['encoding']['min_vol'] = min_vol
config['encoding']['max_vol'] = max_vol
config['encoding']['pad_val'] = pad_val
config['encoding']['optimize'] = optimize
config['recording_style'] = recording_style
config['export_uar'] = export_uar
try:
utacompiler(db_path, config)
except Exception as e:
logger.error(f'Unable to compile UTAU Voice Library: {e}')
sys.exit(1)
def gui() -> None:
with gr.Blocks(title=L('title')) as app:
gr.Markdown(f"# {L('title')}")
gr.Markdown(L('how_to'))
# ROW 1
with gr.Row():
# COLUMN 1
with gr.Column():
db_path = gr.Textbox(label=L('db_path'))
with gr.Accordion(L('config'), open=True):
gr.Markdown(L('config_exp'))
db_name = gr.Textbox(
label=L('db_name'),
placeholder='Utane Uta'
)
with gr.Row():
seed = gr.Number(
label=L('seed'),
value=69420,
)
recording_style = gr.Radio(
choices=['CV', 'VCV', 'CVVC', 'VCCV'],
value='CVVC',
label=L('recording_style'),
interactive=True
)
keep_files = gr.Textbox(
label=L('keep_files'),
placeholder='$read, character.txt, character.yaml, ...'
)
keep_folders = gr.Textbox(
label=L('keep_folders'),
placeholder='omake, extra, ...'
)
pitches = gr.Textbox(
label=L('pitches'),
placeholder='C4, Whisper, CVVC, ...'
)
with gr.Row():
encoding = gr.Radio(
choices=['utf-8', 'shift-jis'],
value='shift-jis',
label=L('file_encoding'),
interactive=True
)
export_uar = gr.Checkbox(
label=L('export_uar'),
value=True,
interactive=True
)
# COLUMN 2
with gr.Column():
with gr.Accordion(L('config_adv'), open=False):
gr.Markdown(L('config_adv_exp'))
with gr.Row():
scramble = gr.Checkbox(
label=L('scramble'),
value=True,
interactive=True,
)
glob_amt = gr.Number(
label=L('glob_amt'),
value=8,
interactive=True,
)
with gr.Row():
pad_val = gr.Slider(
label=L('pad_val'),
value=5.0,
minimum=3.0,
maximum=7.0,
step=0.1,
interactive=True,
)
optimize = gr.Checkbox(
label=L('optimize'),
value=True,
interactive=True,
)
gr.Markdown(f"### {L('encoding_options')}")
encoder_active = gr.Checkbox(
label=L('encoder_active'),
interactive=True,
value=True,
)
gr.Markdown(L('gen_options'))
with gr.Row():
min_frq = gr.Slider(
label=L('min_frq'),
value=200,
minimum=50,
maximum=500,
step=10,
interactive=True,
)
max_frq = gr.Slider(
label=L('max_frq'),
value=1000,
minimum=500,
maximum=1500,
step=10,
interactive=True,
)
with gr.Row():
min_dur = gr.Slider(
label=L('min_dur'),
value=1.0,
minimum=0.5,
maximum=3.0,
step=0.1,
interactive=True,
)
max_dur = gr.Slider(
label=L('max_dur'),
value=4.0,
minimum=1.0,
maximum=10.0,
step=0.1,
interactive=True,
)
with gr.Row():
min_vol = gr.Slider(
label=L('min_vol'),
value=0.2,
minimum=0.1,
maximum=0.4,
step=0.1,
interactive=True,
)
max_vol = gr.Slider(
label=L('max_vol'),
value=0.6,
minimum=0.4,
maximum=1.0,
step=0.1,
interactive=True,
)
run_button = gr.Button(
value=L('run_button'),
)
run_button.click(run_tool, inputs=[
db_path,
db_name,
seed,
recording_style,
keep_files,
keep_folders,
pitches,
encoding,
scramble,
glob_amt,
encoder_active,
min_frq,
max_frq,
min_dur,
max_dur,
min_vol,
max_vol,
pad_val,
optimize,
export_uar,
], outputs=None)
gr.HTML("""
<style>
.bottom-right-inline {
display: inline-block;
align: center;
}
.parent {
padding: 1rem;
position: fixed;
bottom: 0;
right: 0;
padding: 2rem;
margin: 1rem;
z-index: 1000;
}
</style>
<div class="parent">
<div class="bottom-right-inline">
<a href="https://notbyai.fyi/" target="_blank" rel="noopener noreferrer">
<img src="https://github.com/mrtigermeat/UTACompiler/blob/main/src/img/notbyai.png?raw=true" alt="Not by AI badge" width="131">
</a>
</div>
<div class="bottom-right-inline">
<a href="https://tigermeat.xyz/" target="_blank" rel="noopener noreferrer">
<img src="https://github.com/mrtigermeat/UTACompiler/blob/main/src/img/tgm.png?raw=true" alt="Developed by tigermeat" width="42">
</a>
</div>
</div>
""")
app.queue().launch(
server_name="0.0.0.0",
inbrowser=True,
quiet=True,
favicon_path=webapp_src/'tgm.ico',
)
if __name__ == "__main__":
gui()