-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.py
255 lines (229 loc) · 9.37 KB
/
setting.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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
if __name__ == "__main__":
run_bat_content = r'''@echo off
setlocal
__SET_PATH__
call __CONDA__ activate mascotgirl
cd mascotgirl
python mascot.py ^
--select_chara ^
__IGNORE_EXTENSIONS__ ^
--voicevox_url "" ^
--chat_backend "__CHAT_BACKEND__" ^
__CHAT_OPTION__ ^
--chatgpt_log "chatgpt.json" ^
--chatgpt_log_replace ^
--image_pipe_name "\\.\pipe\mascot_image_pipe" ^
--framerate 30 ^
--run_command_reload ^
--run_command "ffmpeg\ffmpeg -y -f rawvideo -pix_fmt rgba -s 512x512 -framerate 30 -thread_queue_size 8192 -i \\.\pipe\mascot_image_pipe -f s16le -ar __AUDIO_FREQ__ -ac 1 -thread_queue_size 8192 -i \\.\pipe\mascot_pipe -c:v copy -c:a copy -f matroska tcp://localhost:55009/stream?listen" ^
--run_command2 "client\MascotGirl_Client.exe -start_local"
cd ..
call __CONDA__ deactivate
endlocal
'''
run_share_bat_content = r'''@echo off
setlocal
__SET_PATH__
call __CONDA__ activate mascotgirl
cd mascotgirl
python mascot.py ^
--select_chara ^
__IGNORE_EXTENSIONS__ ^
--voicevox_url "" ^
--chat_backend "__CHAT_BACKEND__" ^
__CHAT_OPTION__ ^
--ngrok_auth_token "__NGROK_AUTH_TOKEN__" ^
--show_qrcode ^
--chatgpt_log "chatgpt.json" ^
--chatgpt_log_replace ^
--image_pipe_name "\\.\pipe\mascot_image_pipe" ^
--framerate 30 ^
--run_command_reload ^
--run_command "ffmpeg\ffmpeg -y -f rawvideo -pix_fmt rgba -s 512x512 -framerate 30 -thread_queue_size 8192 -i \\.\pipe\mascot_image_pipe -f s16le -ar __AUDIO_FREQ__ -ac 1 -thread_queue_size 8192 -i \\.\pipe\mascot_pipe -auto-alt-ref 0 -deadline realtime -quality realtime -cpu-used 4 -row-mt 1 -crf 30 -b:v 0 -pass 1 -c:v libvpx-vp9 -c:a libopus -f matroska tcp://0.0.0.0:55009/stream?listen"
cd ..
call __CONDA__ deactivate
endlocal
'''
run_local_bat_content = r'''@echo off
setlocal
__SET_PATH__
call __CONDA__ activate mascotgirl
cd mascotgirl
python mascot.py ^
--select_chara ^
__IGNORE_EXTENSIONS__ ^
--voicevox_url "" ^
--chat_backend "__CHAT_BACKEND__" ^
__CHAT_OPTION__ ^
--show_qrcode ^
--chatgpt_log "chatgpt.json" ^
--chatgpt_log_replace ^
--image_pipe_name "\\.\pipe\mascot_image_pipe" ^
--framerate 30 ^
--run_command_reload ^
--run_command "ffmpeg\ffmpeg -y -f rawvideo -pix_fmt rgba -s 512x512 -framerate 30 -thread_queue_size 8192 -i \\.\pipe\mascot_image_pipe -f s16le -ar __AUDIO_FREQ__ -ac 1 -thread_queue_size 8192 -i \\.\pipe\mascot_pipe -auto-alt-ref 0 -deadline realtime -quality realtime -cpu-used 4 -row-mt 1 -crf 30 -b:v 0 -pass 1 -c:v libvpx-vp9 -c:a libopus -f matroska tcp://0.0.0.0:55009/stream?listen"
cd ..
call __CONDA__ deactivate
endlocal
'''
train_style_bert_vits2_bat_content = r'''@echo off
echo NOTE:
echo このバッチファイルは「litagin02/Style-Bert-VITS2」の学習用エディタを起動するだけのものです。
echo NON906作ではないのでご注意ください(本家様に迷惑をかけないようご注意ください)。
setlocal
__SET_PATH__
call __CONDA__ activate mascotgirl
cd mascotgirl/Style-Bert-VITS2
python app.py
cd ../..
call __CONDA__ deactivate
endlocal
'''
uninstall_content = r'''@echo off
setlocal
__SET_PATH__
call __CONDA__ activate mascotgirl
python "mascotgirl/uninstall.py"
if %ERRORLEVEL% neq 1 (
exit /b
)
call __CONDA__ deactivate
del /Q run.bat
del /Q run_share.bat > nul 2>&1
del /Q train_style_bert_vits2.bat
del /Q setting.bat
rd /S /Q mascotgirl
if NOT EXIST "%~dp0.installed\.environment" (
powershell -Command "Start-Process -Wait bin\Miniconda3\Uninstall-Miniconda3.exe /S"
rd /S /Q bin
rd /S /Q .installed
del /Q uninstall.bat && echo アンインストールが完了しました && pause && exit /b
)
rd /S /Q bin
rd /S /Q .installed
conda remove -n mascotgirl --all -y && del /Q uninstall.bat && echo アンインストールが完了しました && pause
endlocal
'''
setting_content = r'''@echo off
setlocal
__SET_PATH__
call __CONDA__ activate mascotgirl
python "mascotgirl/setting.py"
call __CONDA__ deactivate
pause
endlocal
'''
def replace(target: str, content: str):
global run_bat_content
global run_share_bat_content
global run_local_bat_content
global train_style_bert_vits2_bat_content
global uninstall_content
global setting_content
if content is None:
content = ''
run_bat_content = run_bat_content.replace(target, content)
run_share_bat_content = run_share_bat_content.replace(target, content)
run_local_bat_content = run_local_bat_content.replace(target, content)
train_style_bert_vits2_bat_content = train_style_bert_vits2_bat_content.replace(target, content)
uninstall_content = uninstall_content.replace(target, content)
setting_content = setting_content.replace(target, content)
def is_num(s: str):
try:
float(s)
except ValueError:
return False
else:
return True
def is_int_num(s: str):
try:
int(s)
except ValueError:
return False
else:
return True
if os.path.isfile('.installed/.miniconda'):
set_path = r'set PATH=%~dp0bin\Miniconda3;%~dp0bin\Miniconda3\condabin;%~dp0bin\Miniconda3\Library\mingw-w64\bin;%~dp0bin\Miniconda3\Library\usr\bin;%~dp0bin\Miniconda3\Library\bin;%~dp0bin\Miniconda3\Scripts;%PATH%'
replace('__SET_PATH__', set_path)
conda = r'%~dp0bin\Miniconda3\condabin\conda'
replace('__CONDA__', conda)
else:
set_path = r''
replace('__SET_PATH__', set_path)
conda = r'conda'
replace('__CONDA__', conda)
chat_backend_select = -1
while chat_backend_select < 1 or chat_backend_select > 2:
select = input('どのAPIを使用しますか?\n [1. OpenAI API (Assistant) / 2. Google Generative AI] (1): ')
if select is None or select == '' or int(select) == 1:
chat_backend_select = 1
elif int(select) <= 2:
chat_backend_select = int(select)
if chat_backend_select == 1:
replace('__CHAT_BACKEND__', 'OpenAIAssistant')
replace('__CHAT_OPTION__', '''--chatgpt_apikey "__CHATGPT_APIKEY__" ^
--chatgpt_model_name "__CHATGPT_MODEL_NAME__"''')
select = ''
while select is None or select == '':
select = input('OpenAIのAPIキーを入力してください: \n')
replace('__CHATGPT_APIKEY__', select)
select = input('使用するOpenAIのモデル名を入力してください (gpt-3.5-turbo): \n')
if select is None or select == '':
select = 'gpt-3.5-turbo'
replace('__CHATGPT_MODEL_NAME__', select)
else:
replace('__CHAT_BACKEND__', 'GoogleGenerativeAI')
select_apikey = ''
while select_apikey is None or select_apikey == '':
select_apikey = input('Google Generative AIのAPIキーを入力してください: \n')
select = input('使用するAIのモデル名を入力してください (gemini-pro): \n')
if select is None or select == '':
select = 'gemini-pro'
replace('__CHAT_OPTION__', '--google_apikey "' + select_apikey + '" --google_model_name "' + select + '"')
replace('__AUDIO_FREQ__', '44100')
while True:
select = input('リモート接続機能(Androidなど)を使用しますか? [y/N]: ')
if select is None or select == '' or select == 'N' or select == 'n':
save_share_bat = False
break
select = input('ngrokのトークンを入力してください: \n')
if select is not None or select != '':
replace('__NGROK_AUTH_TOKEN__', select)
save_share_bat = True
break
while True:
select = input('拡張機能を有効にしますか? [y/N]: ')
if select is None or select == '' or select == 'N' or select == 'n':
replace('__IGNORE_EXTENSIONS__', '--ignore_extensions')
break
elif select == 'Y' or select == 'y':
replace('__IGNORE_EXTENSIONS__', '')
break
if not '\r\n' in run_bat_content:
run_bat_content.replace('\n', '\r\n')
with open('run.bat', 'w', encoding='shift_jis') as open_file:
open_file.write(run_bat_content)
if save_share_bat:
if not '\r\n' in run_share_bat_content:
run_share_bat_content.replace('\n', '\r\n')
with open('run_share.bat', 'w', encoding='shift_jis') as open_file:
open_file.write(run_share_bat_content)
if not '\r\n' in run_local_bat_content:
run_local_bat_content.replace('\n', '\r\n')
with open('run_local.bat', 'w', encoding='shift_jis') as open_file:
open_file.write(run_local_bat_content)
if not '\r\n' in train_style_bert_vits2_bat_content:
train_style_bert_vits2_bat_content.replace('\n', '\r\n')
with open('train_style_bert_vits2.bat', 'w', encoding='shift_jis') as open_file:
open_file.write(train_style_bert_vits2_bat_content)
if not '\r\n' in uninstall_content:
uninstall_content.replace('\n', '\r\n')
with open('uninstall.bat', 'w', encoding='shift_jis') as open_file:
open_file.write(uninstall_content)
if not '\r\n' in setting_content:
setting_content.replace('\n', '\r\n')
with open('setting.bat', 'w', encoding='shift_jis') as open_file:
open_file.write(setting_content)