forked from Ikaros-521/AI-Vtuber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webui.py
2907 lines (2614 loc) · 226 KB
/
webui.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
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from nicegui import ui, app
import sys, os, json, subprocess, importlib, re, threading, signal
import logging, traceback
import time
import asyncio
# from functools import partial
import http.server
import socketserver
from utils.config import Config
from utils.common import Common
from utils.logger import Configure_logger
from utils.audio import Audio
"""
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@.:;;;++;;;;:,@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@:;+++++;;++++;;;.@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@:++++;;;;;;;;;;+++;,@@@@@@@@@@@@@@@@@
@@@@@@@@@@@.;+++;;;;;;;;;;;;;;++;:@@@@@@@@@@@@@@@@
@@@@@@@@@@;+++;;;;;;;;;;;;;;;;;;++;:@@@@@@@@@@@@@@
@@@@@@@@@:+++;;;;;;;;;;;;;;;;;;;;++;.@@@@@@@@@@@@@
@@@@@@@@;;+;;;;;;;;;;;;;;;;;;;;;;;++:@@@@@@@@@@@@@
@@@@@@@@;+;;;;:::;;;;;;;;;;;;;;;;:;+;,@@@@@@@@@@@@
@@@@@@@:+;;:;;:::;:;;:;;;;::;;:;:::;+;.@@@@@@@@@@@
@@@@@@.;+;::;:,:;:;;+:++:;:::+;:::::++:+@@@@@@@@@@
@@@@@@:+;;:;;:::;;;+%;*?;;:,:;*;;;;:;+;:@@@@@@@@@@
@@@@@@;;;+;;+;:;;;+??;*?++;,:;+++;;;:++:@@@@@@@@@@
@@@@@.++*+;;+;;;;+?;?**??+;:;;+.:+;;;;+;;@@@@@@@@@
@@@@@,+;;;;*++*;+?+;**;:?*;;;;*:,+;;;;+;,@@@@@@@@@
@@@@@,:,+;+?+?++?+;,?#%*??+;;;*;;:+;;;;+:@@@@@@@@@
@@@@@@@:+;*?+?#%;;,,?###@#+;;;*;;,+;;;;+:@@@@@@@@@
@@@@@@@;+;??+%#%;,,,;SSS#S*+++*;..:+;?;+;@@@@@@@@@
@@@@@@@:+**?*?SS,,,,,S#S#+***?*;..;?;**+;@@@@@@@@@
@@@@@@@:+*??*??S,,,,,*%SS+???%++;***;+;;;.@@@@@@@@
@@@@@@@:*?*;*+;%:,,,,;?S?+%%S?%+,:?;+:,,,@@@@@@@@
@@@@@@@,*?,;+;+S:,,,,%?+;S%S%++:+??+:,,,:@@@@@@@@
@@@@@@@,:,@;::;+,,,,,+?%*+S%#?*???*;,,,,,.@@@@@@@@
@@@@@@@@:;,::;;:,,,,,,,,,?SS#??*?+,.,,,:,@@@@@@@@@
@@@@@@;;+;;+:,:%?%*;,,,,SS#%*??%,.,,,,,:@@@@@@@@@
@@@@@.+++,++:;???%S?%;.+#####??;.,,,,,,:@@@@@@@@@
@@@@@:++::??+S#??%#??S%?#@#S*+?*,,,,,,:,@@@@@@@@@@
@@@@@:;;:*?;+%#%?S#??%SS%+#%..;+:,,,,,,@@@@@@@@@@@
@@@@@@,,*S*;?SS?%##%?S#?,.:#+,,+:,,,,,,@@@@@@@@@@@
@@@@@@@;%?%#%?*S##??##?,..*#,,+:,,;*;.@@@@@@@@@@@
@@@@@@.*%??#S*?S#@###%;:*,.:#:,+;:;*+:@@@@@@@@@@@@
@@@@@@,%S??SS%##@@#%S+..;;.,#*;???*?+++:@@@@@@@@@@
@@@@@@:S%??%####@@S,,*,.;*;+#*;+?%??#S%+.@@@@@@@@@
@@@@@@:%???%@###@@?,,:**S##S*;.,%S?;+*?+.,..@@@@@@
@@@@@@;%??%#@###@@#:.;@@#@%%,.,%S*;++*++++;.@@@@@
@@@@@@,%S?S@@###@@@%+#@@#@?;,.:?;??++?%?***+.@@@@@
@@@@@@.*S?S####@@####@@##@?..:*,+:??**%+;;;;..@@@@
@@@@@@:+%?%####@@####@@#@%;:.;;:,+;?**;++;,:;:,@@@
@@@@@@;;*%?%@##@@@###@#S#*:;*+,;.+***?******+:.@@@
@@@@@@:;:??%@###%##@#%++;+*:+;,:;+%?*;+++++;:.@@@@
@@@@@@.+;:?%@@#%;+S*;;,:::**+,;:%??*+.@....@@@@@@@
@@@@@@@;*::?#S#S+;,..,:,;:?+?++*%?+::@@@@@@@@@@@@@
@@@@@@@.+*+++?%S++...,;:***??+;++:.@@@@@@@@@@@@@@@
@@@@@@@@:::..,;+*+;;+*?**+;;;+;:.@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@,+*++;;:,..@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@::,.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"""
"""
全局变量
"""
# 创建一个全局变量,用于表示程序是否正在运行
running_flag = False
# 创建一个子进程对象,用于存储正在运行的外部程序
running_process = None
common = None
config = None
audio = None
my_handle = None
config_path = None
web_server_port = 12345
"""
初始化基本配置
"""
def init():
global config_path, config, common, audio
common = Common()
if getattr(sys, 'frozen', False):
# 当前是打包后的可执行文件
bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(sys.executable)))
file_relative_path = os.path.dirname(os.path.abspath(bundle_dir))
else:
# 当前是源代码
file_relative_path = os.path.dirname(os.path.abspath(__file__))
# logging.info(file_relative_path)
# 初始化文件夹
def init_dir():
# 创建日志文件夹
log_dir = os.path.join(file_relative_path, 'log')
if not os.path.exists(log_dir):
os.makedirs(log_dir)
# 创建音频输出文件夹
audio_out_dir = os.path.join(file_relative_path, 'out')
if not os.path.exists(audio_out_dir):
os.makedirs(audio_out_dir)
# # 创建配置文件夹
# config_dir = os.path.join(file_relative_path, 'config')
# if not os.path.exists(config_dir):
# os.makedirs(config_dir)
init_dir()
# 配置文件路径
config_path = os.path.join(file_relative_path, 'config.json')
audio = Audio(config_path, 2)
# 日志文件路径
file_path = "./log/log-" + common.get_bj_time(1) + ".txt"
Configure_logger(file_path)
# 获取 httpx 库的日志记录器
httpx_logger = logging.getLogger("httpx")
# 设置 httpx 日志记录器的级别为 WARNING
httpx_logger.setLevel(logging.WARNING)
# 获取特定库的日志记录器
watchfiles_logger = logging.getLogger("watchfiles")
# 设置日志级别为WARNING或更高,以屏蔽INFO级别的日志消息
watchfiles_logger.setLevel(logging.WARNING)
logging.debug("配置文件路径=" + str(config_path))
# 实例化配置类
config = Config(config_path)
init()
# 暗夜模式
dark = ui.dark_mode()
"""
通用函数
"""
def textarea_data_change(data):
"""
字符串数组数据格式转换
"""
tmp_str = ""
for tmp in data:
tmp_str = tmp_str + tmp + "\n"
return tmp_str
# web服务线程
async def web_server_thread(web_server_port):
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", web_server_port), Handler) as httpd:
logging.info(f"Web运行在端口:{web_server_port}")
logging.info(f"可以直接访问Live2D页, http://127.0.0.1:{web_server_port}/Live2D/")
httpd.serve_forever()
"""
webui
"""
# 配置
webui_ip = config.get("webui", "ip")
webui_port = config.get("webui", "port")
webui_title = config.get("webui", "title")
# CSS
theme_choose = config.get("webui", "theme", "choose")
tab_panel_css = config.get("webui", "theme", "list", theme_choose, "tab_panel")
card_css = config.get("webui", "theme", "list", theme_choose, "card")
button_bottom_css = config.get("webui", "theme", "list", theme_choose, "button_bottom")
button_bottom_color = config.get("webui", "theme", "list", theme_choose, "button_bottom_color")
button_internal_css = config.get("webui", "theme", "list", theme_choose, "button_internal")
button_internal_color = config.get("webui", "theme", "list", theme_choose, "button_internal_color")
switch_internal_css = config.get("webui", "theme", "list", theme_choose, "switch_internal")
def goto_func_page():
"""
跳转到功能页
"""
global audio
"""
按键调用函数
"""
# 创建一个函数,用于运行外部程序
def run_external_program(config_path="config.json", type="webui"):
global running_flag, running_process
if running_flag:
if type == "webui":
ui.notify(position="top", type="warning", message="运行中,请勿重复运行")
return
try:
running_flag = True
# 在这里指定要运行的程序和参数
# 例如,运行一个名为 "bilibili.py" 的 Python 脚本
running_process = subprocess.Popen(["python", f"{select_platform.value}.py"])
if type == "webui":
ui.notify(position="top", type="positive", message="程序开始运行")
logging.info("程序开始运行")
return {"code": 200, "msg": "程序开始运行"}
except Exception as e:
if type == "webui":
ui.notify(position="top", type="negative", message=f"错误:{e}")
logging.error(traceback.format_exc())
running_flag = False
return {"code": -1, "msg": f"运行失败!{e}"}
# 定义一个函数,用于停止正在运行的程序
def stop_external_program(type="webui"):
global running_flag, running_process
if running_flag:
try:
running_process.terminate() # 终止子进程
running_flag = False
if type == "webui":
ui.notify(position="top", type="positive", message="程序已停止")
logging.info("程序已停止")
except Exception as e:
if type == "webui":
ui.notify(position="top", type="negative", message=f"停止错误:{e}")
logging.error(f"停止错误:{e}")
return {"code": -1, "msg": f"重启失败!{e}"}
# 开关灯
def change_light_status(type="webui"):
if dark.value:
button_light.set_text("关灯")
else:
button_light.set_text("开灯")
dark.toggle()
# 重启
def restart_application(type="webui"):
try:
# 先停止运行
stop_external_program(type)
logging.info(f"重启webui")
if type == "webui":
ui.notify(position="top", type="ongoing", message=f"重启中...")
python = sys.executable
os.execl(python, python, *sys.argv) # Start a new instance of the application
except Exception as e:
logging.error(traceback.format_exc())
return {"code": -1, "msg": f"重启失败!{e}"}
# 恢复出厂配置
def factory(src_path='config.json.bak', dst_path='config.json', type="webui"):
# src_path = 'config.json.bak'
# dst_path = 'config.json'
try:
with open(src_path, 'r', encoding="utf-8") as source:
with open(dst_path, 'w', encoding="utf-8") as destination:
destination.write(source.read())
logging.info("恢复出厂配置成功!")
if type == "webui":
ui.notify(position="top", type="positive", message=f"恢复出厂配置成功!")
# 重启
restart_application()
return {"code": 200, "msg": "恢复出厂配置成功!"}
except Exception as e:
logging.error(f"恢复出厂配置失败!\n{e}")
if type == "webui":
ui.notify(position="top", type="negative", message=f"恢复出厂配置失败!\n{e}")
return {"code": -1, "msg": f"恢复出厂配置失败!\n{e}"}
# openai 测试key可用性
def test_openai_key():
data_json = {
"base_url": input_openai_api.value,
"api_keys": textarea_openai_api_key.value,
"model": select_chatgpt_model.value,
"temperature": round(float(input_chatgpt_temperature.value), 1),
"max_tokens": int(input_chatgpt_max_tokens.value),
"top_p": round(float(input_chatgpt_top_p.value), 1),
"presence_penalty": round(float(input_chatgpt_presence_penalty.value), 1),
"frequency_penalty": round(float(input_chatgpt_frequency_penalty.value), 1),
"preset": input_chatgpt_preset.value
}
if common.test_openai_key(data_json):
ui.notify(position="top", type="positive", message=f"测试通过!")
else:
ui.notify(position="top", type="negative", message=f"测试失败!")
"""
API
"""
from starlette.requests import Request
"""
系统命令
type 命令类型(run/stop/restart/factory)
data 传入的json
data_json = {
"type": "命令名",
"data": {
"key": "value"
}
}
return:
{"code": 200, "msg": "成功"}
{"code": -1, "msg": "失败"}
"""
@app.post('/sys_cmd')
async def sys_cmd(request: Request):
try:
data_json = await request.json()
logging.info(f'收到数据:{data_json}')
logging.info(f"开始执行 {data_json['type']}命令...")
resp_json = {}
if data_json['type'] == 'run':
"""
{
"type": "run",
"data": {
"config_path": "config.json"
}
}
"""
# 运行
resp_json = run_external_program(data_json['data']['config_path'], type="api")
elif data_json['type'] =='stop':
"""
{
"type": "stop",
"data": {
"config_path": "config.json"
}
}
"""
# 停止
resp_json = stop_external_program(type="api")
elif data_json['type'] =='restart':
"""
{
"type": "restart",
"api_type": "webui",
"data": {
"config_path": "config.json"
}
}
"""
# 重启
resp_json = restart_application(type=data_json['api_type'])
elif data_json['type'] =='factory':
"""
{
"type": "factory",
"api_type": "webui",
"data": {
"src_path": "config.json.bak",
"dst_path": "config.json"
}
}
"""
# 恢复出厂
resp_json = factory(data_json['data']['src_path'], data_json['data']['dst_path'], type="api")
return resp_json
except Exception as e:
logging.error(traceback.format_exc())
return {"code": -1, "msg": f"{data_json['type']}执行失败!{e}"}
"""
文案页
"""
# 文案页-增加
def copywriting_add():
data_len = len(copywriting_config_var)
tmp_config = {
"file_path": f"data/copywriting{int(data_len / 5) + 1}/",
"audio_path": f"out/copywriting{int(data_len / 5) + 1}/",
"continuous_play_num": 2,
"max_play_time": 10.0,
"play_list": []
}
with copywriting_config_card.style(card_css):
with ui.row():
copywriting_config_var[str(data_len)] = ui.input(label=f"文案存储路径#{int(data_len / 5) + 1}", value=tmp_config["file_path"], placeholder='文案文件存储路径。不建议更改。').style("width:200px;")
copywriting_config_var[str(data_len + 1)] = ui.input(label=f"音频存储路径#{int(data_len / 5) + 1}", value=tmp_config["audio_path"], placeholder='文案音频文件存储路径。不建议更改。').style("width:200px;")
copywriting_config_var[str(data_len + 2)] = ui.input(label=f"连续播放数#{int(data_len / 5) + 1}", value=tmp_config["continuous_play_num"], placeholder='文案播放列表中连续播放的音频文件个数,如果超过了这个个数就会切换下一个文案列表').style("width:200px;")
copywriting_config_var[str(data_len + 3)] = ui.input(label=f"连续播放时间#{int(data_len / 5) + 1}", value=tmp_config["max_play_time"], placeholder='文案播放列表中连续播放音频的时长,如果超过了这个时长就会切换下一个文案列表').style("width:200px;")
copywriting_config_var[str(data_len + 4)] = ui.textarea(label=f"播放列表#{int(data_len / 5) + 1}", value=textarea_data_change(tmp_config["play_list"]), placeholder='此处填写需要播放的音频文件全名,填写完毕后点击 保存配置。文件全名从音频列表中复制,换行分隔,请勿随意填写').style("width:500px;")
# 文案页-删除
def copywriting_del(index):
try:
copywriting_config_card.remove(int(index) - 1)
# 删除操作
keys_to_delete = [str(5 * (int(index) - 1) + i) for i in range(5)]
for key in keys_to_delete:
if key in copywriting_config_var:
del copywriting_config_var[key]
# 重新编号剩余的键
updates = {}
for key in sorted(copywriting_config_var.keys(), key=int):
new_key = str(int(key) - 5 if int(key) > int(keys_to_delete[-1]) else key)
updates[new_key] = copywriting_config_var[key]
# 应用更新
copywriting_config_var.clear()
copywriting_config_var.update(updates)
except Exception as e:
ui.notify(position="top", type="negative", message=f"错误,索引值配置有误:{e}")
logging.error(traceback.format_exc())
# 文案页-循环播放
def copywriting_loop_play():
if running_flag != 1:
ui.notify(position="top", type="warning", message=f"请先点击“一键运行”,然后再进行播放")
return
logging.info("开始循环播放文案~")
ui.notify(position="top", type="positive", message="开始循环播放文案~")
audio.unpause_copywriting_play()
# 文案页-暂停播放
def copywriting_pause_play():
if running_flag != 1:
ui.notify(position="top", type="warning", message=f"请先点击“一键运行”,然后再进行暂停")
return
audio.pause_copywriting_play()
logging.info("暂停文案完毕~")
ui.notify(position="top", type="positive", message="暂停文案完毕~")
"""
配置操作
"""
# 配置检查
def check_config():
# 通用配置 页面
if select_platform.value == 'bilibili2' and select_bilibili_login_type.value == 'cookie' and input_bilibili_cookie.value == '':
ui.notify(position="top", type="warning", message="请先前往 通用配置-哔哩哔哩,填写B站cookie")
return False
elif select_platform.value == 'bilibili2' and select_bilibili_login_type.value == 'open_live' and \
(input_bilibili_open_live_ACCESS_KEY_ID.value == '' or input_bilibili_open_live_ACCESS_KEY_SECRET.value == '' or \
input_bilibili_open_live_APP_ID.value == '' or input_bilibili_open_live_ROOM_OWNER_AUTH_CODE.value == ''):
ui.notify(position="top", type="warning", message="请先前往 通用配置-哔哩哔哩,填写开放平台配置")
return False
return True
# 保存配置
def save_config():
global config, config_path
# 配置检查
if not check_config():
return
try:
with open(config_path, 'r', encoding="utf-8") as config_file:
config_data = json.load(config_file)
except Exception as e:
logging.error(f"无法读取配置文件!\n{e}")
ui.notify(position="top", type="negative", message=f"无法读取配置文件!{e}")
return False
def common_textarea_handle(content):
"""通用的textEdit 多行文本内容处理
Args:
content (str): 原始多行文本内容
Returns:
_type_: 处理好的多行文本内容
"""
# 通用多行分隔符
separators = [" ", "\n"]
ret = [token.strip() for separator in separators for part in content.split(separator) if (token := part.strip())]
if 0 != len(ret):
ret = ret[1:]
return ret
try:
"""
通用配置
"""
if True:
config_data["platform"] = select_platform.value
config_data["room_display_id"] = input_room_display_id.value
config_data["chat_type"] = select_chat_type.value
config_data["visual_body"] = select_visual_body.value
config_data["need_lang"] = select_need_lang.value
config_data["before_prompt"] = input_before_prompt.value
config_data["after_prompt"] = input_after_prompt.value
config_data["audio_synthesis_type"] = select_audio_synthesis_type.value
# 哔哩哔哩
config_data["bilibili"]["login_type"] = select_bilibili_login_type.value
config_data["bilibili"]["cookie"] = input_bilibili_cookie.value
config_data["bilibili"]["ac_time_value"] = input_bilibili_ac_time_value.value
config_data["bilibili"]["username"] = input_bilibili_username.value
config_data["bilibili"]["password"] = input_bilibili_password.value
config_data["bilibili"]["open_live"]["ACCESS_KEY_ID"] = input_bilibili_open_live_ACCESS_KEY_ID.value
config_data["bilibili"]["open_live"]["ACCESS_KEY_SECRET"] = input_bilibili_open_live_ACCESS_KEY_SECRET.value
config_data["bilibili"]["open_live"]["APP_ID"] = int(input_bilibili_open_live_APP_ID.value)
config_data["bilibili"]["open_live"]["ROOM_OWNER_AUTH_CODE"] = input_bilibili_open_live_ROOM_OWNER_AUTH_CODE.value
# twitch
config_data["twitch"]["token"] = input_twitch_token.value
config_data["twitch"]["user"] = input_twitch_user.value
config_data["twitch"]["proxy_server"] = input_twitch_proxy_server.value
config_data["twitch"]["proxy_port"] = input_twitch_proxy_port.value
# 音频播放
config_data["play_audio"]["enable"] = switch_play_audio_enable.value
config_data["play_audio"]["text_split_enable"] = switch_play_audio_text_split_enable.value
config_data["play_audio"]["normal_interval"] = round(float(input_play_audio_normal_interval.value), 2)
config_data["play_audio"]["out_path"] = input_play_audio_out_path.value
config_data["play_audio"]["player"] = select_play_audio_player.value
# audio_player
config_data["audio_player"]["api_ip_port"] = input_audio_player_api_ip_port.value
# 念弹幕
config_data["read_comment"]["enable"] = switch_read_comment_enable.value
config_data["read_comment"]["read_username_enable"] = switch_read_comment_read_username_enable.value
config_data["read_comment"]["username_max_len"] = int(input_read_comment_username_max_len.value)
config_data["read_comment"]["voice_change"] = switch_read_comment_voice_change.value
config_data["read_comment"]["read_username_copywriting"] = common_textarea_handle(textarea_read_comment_read_username_copywriting.value)
# 回复时念用户名
config_data["read_user_name"]["enable"] = switch_read_user_name_enable.value
config_data["read_user_name"]["username_max_len"] = int(input_read_user_name_username_max_len.value)
config_data["read_user_name"]["voice_change"] = switch_read_user_name_voice_change.value
config_data["read_user_name"]["reply_before"] = common_textarea_handle(textarea_read_user_name_reply_before.value)
config_data["read_user_name"]["reply_after"] = common_textarea_handle(textarea_read_user_name_reply_after.value)
# 日志
config_data["comment_log_type"] = select_comment_log_type.value
config_data["captions"]["enable"] = switch_captions_enable.value
config_data["captions"]["file_path"] = input_captions_file_path.value
# 本地问答
config_data["local_qa"]["text"]["enable"] = switch_local_qa_text_enable.value
local_qa_text_type = select_local_qa_text_type.value
if local_qa_text_type == "自定义json":
config_data["local_qa"]["text"]["type"] = "json"
elif local_qa_text_type == "一问一答":
config_data["local_qa"]["text"]["type"] = "text"
config_data["local_qa"]["text"]["file_path"] = input_local_qa_text_file_path.value
config_data["local_qa"]["text"]["similarity"] = round(float(input_local_qa_text_similarity.value), 2)
config_data["local_qa"]["text"]["username_max_len"] = int(input_local_qa_text_username_max_len.value)
config_data["local_qa"]["audio"]["enable"] = switch_local_qa_audio_enable.value
config_data["local_qa"]["audio"]["file_path"] = input_local_qa_audio_file_path.value
config_data["local_qa"]["audio"]["similarity"] = round(float(input_local_qa_audio_similarity.value), 2)
# 过滤
config_data["filter"]["before_must_str"] = common_textarea_handle(textarea_filter_before_must_str.value)
config_data["filter"]["after_must_str"] = common_textarea_handle(textarea_filter_after_must_str.value)
config_data["filter"]["before_filter_str"] = common_textarea_handle(textarea_filter_before_filter_str.value)
config_data["filter"]["after_filter_str"] = common_textarea_handle(textarea_filter_after_filter_str.value)
config_data["filter"]["badwords_path"] = input_filter_badwords_path.value
config_data["filter"]["bad_pinyin_path"] = input_filter_bad_pinyin_path.value
config_data["filter"]["max_len"] = int(input_filter_max_len.value)
config_data["filter"]["max_char_len"] = int(input_filter_max_char_len.value)
config_data["filter"]["comment_forget_duration"] = round(float(input_filter_comment_forget_duration.value), 2)
config_data["filter"]["comment_forget_reserve_num"] = int(input_filter_comment_forget_reserve_num.value)
config_data["filter"]["gift_forget_duration"] = round(float(input_filter_gift_forget_duration.value), 2)
config_data["filter"]["gift_forget_reserve_num"] = int(input_filter_gift_forget_reserve_num.value)
config_data["filter"]["entrance_forget_duration"] = round(float(input_filter_entrance_forget_duration.value), 2)
config_data["filter"]["entrance_forget_reserve_num"] = int(input_filter_entrance_forget_reserve_num.value)
config_data["filter"]["follow_forget_duration"] = round(float(input_filter_follow_forget_duration.value), 2)
config_data["filter"]["follow_forget_reserve_num"] = int(input_filter_follow_forget_reserve_num.value)
config_data["filter"]["talk_forget_duration"] = round(float(input_filter_talk_forget_duration.value), 2)
config_data["filter"]["talk_forget_reserve_num"] = int(input_filter_talk_forget_reserve_num.value)
config_data["filter"]["schedule_forget_duration"] = round(float(input_filter_schedule_forget_duration.value), 2)
config_data["filter"]["schedule_forget_reserve_num"] = int(input_filter_schedule_forget_reserve_num.value)
# 答谢
config_data["thanks"]["username_max_len"] = int(input_thanks_username_max_len.value)
config_data["thanks"]["entrance_enable"] = switch_thanks_entrance_enable.value
config_data["thanks"]["entrance_random"] = switch_thanks_entrance_random.value
config_data["thanks"]["entrance_copy"] = common_textarea_handle(textarea_thanks_entrance_copy.value)
config_data["thanks"]["gift_enable"] = switch_thanks_gift_enable.value
config_data["thanks"]["gift_random"] = switch_thanks_gift_random.value
config_data["thanks"]["gift_copy"] = common_textarea_handle(textarea_thanks_gift_copy.value)
config_data["thanks"]["lowest_price"] = round(float(input_thanks_lowest_price.value), 2)
config_data["thanks"]["follow_enable"] = switch_thanks_follow_enable.value
config_data["thanks"]["follow_random"] = switch_thanks_follow_random.value
config_data["thanks"]["follow_copy"] = common_textarea_handle(textarea_thanks_follow_copy.value)
# 音频随机变速
config_data["audio_random_speed"]["normal"]["enable"] = switch_audio_random_speed_normal_enable.value
config_data["audio_random_speed"]["normal"]["speed_min"] = round(float(input_audio_random_speed_normal_speed_min.value), 2)
config_data["audio_random_speed"]["normal"]["speed_max"] = round(float(input_audio_random_speed_normal_speed_max.value), 2)
config_data["audio_random_speed"]["copywriting"]["enable"] = switch_audio_random_speed_copywriting_enable.value
config_data["audio_random_speed"]["copywriting"]["speed_min"] = round(float(input_audio_random_speed_copywriting_speed_min.value), 2)
config_data["audio_random_speed"]["copywriting"]["speed_max"] = round(float(input_audio_random_speed_copywriting_speed_max.value), 2)
# 点歌模式
config_data["choose_song"]["enable"] = switch_choose_song_enable.value
config_data["choose_song"]["start_cmd"] = common_textarea_handle(textarea_choose_song_start_cmd.value)
config_data["choose_song"]["stop_cmd"] = common_textarea_handle(textarea_choose_song_stop_cmd.value)
config_data["choose_song"]["random_cmd"] = common_textarea_handle(textarea_choose_song_random_cmd.value)
config_data["choose_song"]["song_path"] = input_choose_song_song_path.value
config_data["choose_song"]["match_fail_copy"] = input_choose_song_match_fail_copy.value
config_data["choose_song"]["similarity"] = round(float(input_choose_song_similarity.value), 2)
# 定时任务
tmp_arr = []
# logging.info(schedule_var)
for index in range(len(schedule_var) // 3):
tmp_json = {
"enable": False,
"time": 60,
"copy": []
}
tmp_json["enable"] = schedule_var[str(3 * index)].value
tmp_json["time"] = round(float(schedule_var[str(3 * index + 1)].value), 1)
tmp_json["copy"] = common_textarea_handle(schedule_var[str(3 * index + 2)].value)
tmp_arr.append(tmp_json)
# logging.info(tmp_arr)
config_data["schedule"] = tmp_arr
# 闲时任务
config_data["idle_time_task"]["enable"] = switch_idle_time_task_enable.value
config_data["idle_time_task"]["idle_time"] = input_idle_time_task_idle_time.value
config_data["idle_time_task"]["random_time"] = switch_idle_time_task_random_time.value
config_data["idle_time_task"]["comment"]["enable"] = switch_idle_time_task_comment_enable.value
config_data["idle_time_task"]["comment"]["random"] = switch_idle_time_task_comment_random.value
config_data["idle_time_task"]["comment"]["copy"] = common_textarea_handle(textarea_idle_time_task_comment_copy.value)
config_data["idle_time_task"]["local_audio"]["enable"] = switch_idle_time_task_local_audio_enable.value
config_data["idle_time_task"]["local_audio"]["random"] = switch_idle_time_task_local_audio_random.value
config_data["idle_time_task"]["local_audio"]["path"] = common_textarea_handle(textarea_idle_time_task_local_audio_path.value)
# SD
config_data["sd"]["enable"] = switch_sd_enable.value
config_data["sd"]["prompt_llm"]["type"] = select_sd_prompt_llm_type.value
config_data["sd"]["prompt_llm"]["before_prompt"] = input_sd_prompt_llm_before_prompt.value
config_data["sd"]["prompt_llm"]["after_prompt"] = input_sd_prompt_llm_after_prompt.value
config_data["sd"]["trigger"] = input_sd_trigger.value
config_data["sd"]["ip"] = input_sd_ip.value
sd_port = input_sd_port.value
config_data["sd"]["port"] = int(sd_port)
config_data["sd"]["negative_prompt"] = input_sd_negative_prompt.value
config_data["sd"]["seed"] = float(input_sd_seed.value)
# 获取多行文本输入框的内容
config_data["sd"]["styles"] = common_textarea_handle(textarea_sd_styles.value)
config_data["sd"]["cfg_scale"] = int(input_sd_cfg_scale.value)
config_data["sd"]["steps"] = int(input_sd_steps.value)
config_data["sd"]["hr_resize_x"] = int(input_sd_hr_resize_x.value)
config_data["sd"]["hr_resize_y"] = int(input_sd_hr_resize_y.value)
config_data["sd"]["enable_hr"] = switch_sd_enable_hr.value
config_data["sd"]["hr_scale"] = int(input_sd_hr_scale.value)
config_data["sd"]["hr_second_pass_steps"] = int(input_sd_hr_second_pass_steps.value)
config_data["sd"]["denoising_strength"] = round(float(input_sd_denoising_strength.value), 1)
config_data["sd"]["save_enable"] = switch_sd_save_enable.value
config_data["sd"]["loop_cover"] = switch_sd_loop_cover.value
config_data["sd"]["save_path"] = input_sd_save_path.value
# 动态文案
config_data["trends_copywriting"]["enable"] = switch_trends_copywriting_enable.value
config_data["trends_copywriting"]["random_play"] = switch_trends_copywriting_random_play.value
config_data["trends_copywriting"]["play_interval"] = int(input_trends_copywriting_play_interval.value)
tmp_arr = []
for index in range(len(trends_copywriting_copywriting_var) // 3):
tmp_json = {
"folder_path": "",
"prompt_change_enable": False,
"prompt_change_content": ""
}
tmp_json["folder_path"] = trends_copywriting_copywriting_var[str(3 * index)].value
tmp_json["prompt_change_enable"] = trends_copywriting_copywriting_var[str(3 * index + 1)].value
tmp_json["prompt_change_content"] = trends_copywriting_copywriting_var[str(3 * index + 2)].value
tmp_arr.append(tmp_json)
# logging.info(tmp_arr)
config_data["trends_copywriting"]["copywriting"] = tmp_arr
# web字幕打印机
config_data["web_captions_printer"]["enable"] = switch_web_captions_printer_enable.value
config_data["web_captions_printer"]["api_ip_port"] = input_web_captions_printer_api_ip_port.value
# 数据库
config_data["database"]["path"] = input_database_path.value
config_data["database"]["comment_enable"] = switch_database_comment_enable.value
config_data["database"]["entrance_enable"] = switch_database_entrance_enable.value
config_data["database"]["gift_enable"] = switch_database_gift_enable.value
# 按键映射
config_data["key_mapping"]["enable"] = switch_key_mapping_enable.value
config_data["key_mapping"]["type"] = select_key_mapping_type.value
# logging.info(select_key_mapping_type.value)
config_data["key_mapping"]["start_cmd"] = input_key_mapping_start_cmd.value
tmp_arr = []
# logging.info(key_mapping_config_var)
for index in range(len(key_mapping_config_var) // 3):
tmp_json = {
"keywords": [],
"keys": [],
"similarity": 1
}
tmp_json["keywords"] = common_textarea_handle(key_mapping_config_var[str(3 * index)].value)
tmp_json["keys"] = common_textarea_handle(key_mapping_config_var[str(3 * index + 1)].value)
tmp_json["similarity"] = key_mapping_config_var[str(3 * index + 2)].value
tmp_arr.append(tmp_json)
# logging.info(tmp_arr)
config_data["key_mapping"]["config"] = tmp_arr
# 动态配置
config_data["trends_config"]["enable"] = switch_trends_config_enable.value
tmp_arr = []
# logging.info(trends_config_path_var)
for index in range(len(trends_config_path_var) // 2):
tmp_json = {
"online_num": "0-999999999",
"path": "config.json"
}
tmp_json["online_num"] = trends_config_path_var[str(2 * index)].value
tmp_json["path"] = trends_config_path_var[str(2 * index + 1)].value
tmp_arr.append(tmp_json)
# logging.info(tmp_arr)
config_data["trends_config"]["path"] = tmp_arr
# 异常报警
config_data["abnormal_alarm"]["platform"]["enable"] = switch_abnormal_alarm_platform_enable.value
config_data["abnormal_alarm"]["platform"]["type"] = select_abnormal_alarm_platform_type.value
config_data["abnormal_alarm"]["platform"]["start_alarm_error_num"] = int(input_abnormal_alarm_platform_start_alarm_error_num.value)
config_data["abnormal_alarm"]["platform"]["auto_restart_error_num"] = int(input_abnormal_alarm_platform_auto_restart_error_num.value)
config_data["abnormal_alarm"]["platform"]["local_audio_path"] = input_abnormal_alarm_platform_local_audio_path.value
config_data["abnormal_alarm"]["llm"]["enable"] = switch_abnormal_alarm_llm_enable.value
config_data["abnormal_alarm"]["llm"]["type"] = select_abnormal_alarm_llm_type.value
config_data["abnormal_alarm"]["llm"]["start_alarm_error_num"] = int(input_abnormal_alarm_llm_start_alarm_error_num.value)
config_data["abnormal_alarm"]["llm"]["auto_restart_error_num"] = int(input_abnormal_alarm_llm_auto_restart_error_num.value)
config_data["abnormal_alarm"]["llm"]["local_audio_path"] = input_abnormal_alarm_llm_local_audio_path.value
config_data["abnormal_alarm"]["tts"]["enable"] = switch_abnormal_alarm_tts_enable.value
config_data["abnormal_alarm"]["tts"]["type"] = select_abnormal_alarm_tts_type.value
config_data["abnormal_alarm"]["tts"]["start_alarm_error_num"] = int(input_abnormal_alarm_tts_start_alarm_error_num.value)
config_data["abnormal_alarm"]["tts"]["auto_restart_error_num"] = int(input_abnormal_alarm_tts_auto_restart_error_num.value)
config_data["abnormal_alarm"]["tts"]["local_audio_path"] = input_abnormal_alarm_tts_local_audio_path.value
config_data["abnormal_alarm"]["svc"]["enable"] = switch_abnormal_alarm_svc_enable.value
config_data["abnormal_alarm"]["svc"]["type"] = select_abnormal_alarm_svc_type.value
config_data["abnormal_alarm"]["svc"]["start_alarm_error_num"] = int(input_abnormal_alarm_svc_start_alarm_error_num.value)
config_data["abnormal_alarm"]["svc"]["auto_restart_error_num"] = int(input_abnormal_alarm_svc_auto_restart_error_num.value)
config_data["abnormal_alarm"]["svc"]["local_audio_path"] = input_abnormal_alarm_svc_local_audio_path.value
config_data["abnormal_alarm"]["visual_body"]["enable"] = switch_abnormal_alarm_visual_body_enable.value
config_data["abnormal_alarm"]["visual_body"]["type"] = select_abnormal_alarm_visual_body_type.value
config_data["abnormal_alarm"]["visual_body"]["start_alarm_error_num"] = int(input_abnormal_alarm_visual_body_start_alarm_error_num.value)
config_data["abnormal_alarm"]["visual_body"]["auto_restart_error_num"] = int(input_abnormal_alarm_visual_body_auto_restart_error_num.value)
config_data["abnormal_alarm"]["visual_body"]["local_audio_path"] = input_abnormal_alarm_visual_body_local_audio_path.value
config_data["abnormal_alarm"]["other"]["enable"] = switch_abnormal_alarm_other_enable.value
config_data["abnormal_alarm"]["other"]["type"] = select_abnormal_alarm_other_type.value
config_data["abnormal_alarm"]["other"]["start_alarm_error_num"] = int(input_abnormal_alarm_other_start_alarm_error_num.value)
config_data["abnormal_alarm"]["other"]["auto_restart_error_num"] = int(input_abnormal_alarm_other_auto_restart_error_num.value)
config_data["abnormal_alarm"]["other"]["local_audio_path"] = input_abnormal_alarm_other_local_audio_path.value
"""
LLM
"""
if True:
config_data["openai"]["api"] = input_openai_api.value
config_data["openai"]["api_key"] = common_textarea_handle(textarea_openai_api_key.value)
# logging.info(select_chatgpt_model.value)
config_data["chatgpt"]["model"] = select_chatgpt_model.value
config_data["chatgpt"]["temperature"] = round(float(input_chatgpt_temperature.value), 1)
config_data["chatgpt"]["max_tokens"] = int(input_chatgpt_max_tokens.value)
config_data["chatgpt"]["top_p"] = round(float(input_chatgpt_top_p.value), 1)
config_data["chatgpt"]["presence_penalty"] = round(float(input_chatgpt_presence_penalty.value), 1)
config_data["chatgpt"]["frequency_penalty"] = round(float(input_chatgpt_frequency_penalty.value), 1)
config_data["chatgpt"]["preset"] = input_chatgpt_preset.value
config_data["claude"]["slack_user_token"] = input_claude_slack_user_token.value
config_data["claude"]["bot_user_id"] = input_claude_bot_user_id.value
config_data["claude2"]["cookie"] = input_claude2_cookie.value
config_data["claude2"]["use_proxy"] = switch_claude2_use_proxy.value
config_data["claude2"]["proxies"]["http"] = input_claude2_proxies_http.value
config_data["claude2"]["proxies"]["https"] = input_claude2_proxies_https.value
config_data["claude2"]["proxies"]["socks5"] = input_claude2_proxies_socks5.value
config_data["chatglm"]["api_ip_port"] = input_chatglm_api_ip_port.value
config_data["chatglm"]["max_length"] = int(input_chatglm_max_length.value)
config_data["chatglm"]["top_p"] = round(float(input_chatglm_top_p.value), 1)
config_data["chatglm"]["temperature"] = round(float(input_chatglm_temperature.value), 2)
config_data["chatglm"]["history_enable"] = switch_chatglm_history_enable.value
config_data["chatglm"]["history_max_len"] = int(input_chatglm_history_max_len.value)
config_data["chat_with_file"]["chat_mode"] = select_chat_with_file_chat_mode.value
config_data["chat_with_file"]["data_path"] = input_chat_with_file_data_path.value
config_data["chat_with_file"]["separator"] = input_chat_with_file_separator.value
config_data["chat_with_file"]["chunk_size"] = int(input_chat_with_file_chunk_size.value)
config_data["chat_with_file"]["chunk_overlap"] = int(input_chat_with_file_chunk_overlap.value)
config_data["chat_with_file"]["local_vector_embedding_model"] = select_chat_with_file_local_vector_embedding_model.value
config_data["chat_with_file"]["chain_type"] = input_chat_with_file_chain_type.value
config_data["chat_with_file"]["question_prompt"] = input_chat_with_file_question_prompt.value
config_data["chat_with_file"]["local_max_query"] = int(input_chat_with_file_local_max_query.value)
config_data["chat_with_file"]["show_token_cost"] = switch_chat_with_file_show_token_cost.value
config_data["chatterbot"]["name"] = input_chatterbot_name.value
config_data["chatterbot"]["db_path"] = input_chatterbot_db_path.value
config_data["text_generation_webui"]["type"] = select_text_generation_webui_type.value
config_data["text_generation_webui"]["api_ip_port"] = input_text_generation_webui_api_ip_port.value
config_data["text_generation_webui"]["max_new_tokens"] = int(input_text_generation_webui_max_new_tokens.value)
config_data["text_generation_webui"]["history_enable"] = switch_text_generation_webui_history_enable.value
config_data["text_generation_webui"]["history_max_len"] = int(input_text_generation_webui_history_max_len.value)
config_data["text_generation_webui"]["mode"] = select_text_generation_webui_mode.value
config_data["text_generation_webui"]["character"] = input_text_generation_webui_character.value
config_data["text_generation_webui"]["instruction_template"] = input_text_generation_webui_instruction_template.value
config_data["text_generation_webui"]["your_name"] = input_text_generation_webui_your_name.value
config_data["text_generation_webui"]["top_p"] = round(float(input_text_generation_webui_top_p.value), 2)
config_data["text_generation_webui"]["top_k"] = int(input_text_generation_webui_top_k.value)
config_data["text_generation_webui"]["temperature"] = round(float(input_text_generation_webui_temperature.value), 2)
config_data["text_generation_webui"]["seed"] = float(input_text_generation_webui_seed.value)
config_data["sparkdesk"]["type"] = select_sparkdesk_type.value
config_data["sparkdesk"]["cookie"] = input_sparkdesk_cookie.value
config_data["sparkdesk"]["fd"] = input_sparkdesk_fd.value
config_data["sparkdesk"]["GtToken"] = input_sparkdesk_GtToken.value
config_data["sparkdesk"]["app_id"] = input_sparkdesk_app_id.value
config_data["sparkdesk"]["api_secret"] = input_sparkdesk_api_secret.value
config_data["sparkdesk"]["api_key"] = input_sparkdesk_api_key.value
config_data["sparkdesk"]["version"] = round(float(select_sparkdesk_version.value), 1)
config_data["langchain_chatglm"]["api_ip_port"] = input_langchain_chatglm_api_ip_port.value
config_data["langchain_chatglm"]["chat_type"] = select_langchain_chatglm_chat_type.value
config_data["langchain_chatglm"]["knowledge_base_id"] = input_langchain_chatglm_knowledge_base_id.value
config_data["langchain_chatglm"]["history_enable"] = switch_langchain_chatglm_history_enable.value
config_data["langchain_chatglm"]["history_max_len"] = int(input_langchain_chatglm_history_max_len.value)
config_data["langchain_chatchat"]["api_ip_port"] = input_langchain_chatchat_api_ip_port.value
config_data["langchain_chatchat"]["chat_type"] = select_langchain_chatchat_chat_type.value
config_data["langchain_chatchat"]["history_enable"] = switch_langchain_chatchat_history_enable.value
config_data["langchain_chatchat"]["history_max_len"] = int(input_langchain_chatchat_history_max_len.value)
config_data["langchain_chatchat"]["llm"]["model_name"] = input_langchain_chatchat_llm_model_name.value
config_data["langchain_chatchat"]["llm"]["temperature"] = round(float(input_langchain_chatchat_llm_temperature.value), 2)
config_data["langchain_chatchat"]["llm"]["max_tokens"] = int(input_langchain_chatchat_llm_max_tokens.value)
config_data["langchain_chatchat"]["llm"]["prompt_name"] = input_langchain_chatchat_llm_prompt_name.value
config_data["langchain_chatchat"]["knowledge_base"]["knowledge_base_name"] = input_langchain_chatchat_knowledge_base_knowledge_base_name.value
config_data["langchain_chatchat"]["knowledge_base"]["top_k"] = int(input_langchain_chatchat_knowledge_base_top_k.value)
config_data["langchain_chatchat"]["knowledge_base"]["score_threshold"] = round(float(input_langchain_chatchat_knowledge_base_score_threshold.value), 2)
config_data["langchain_chatchat"]["knowledge_base"]["model_name"] = input_langchain_chatchat_knowledge_base_model_name.value
config_data["langchain_chatchat"]["knowledge_base"]["temperature"] = round(float(input_langchain_chatchat_knowledge_base_temperature.value), 2)
config_data["langchain_chatchat"]["knowledge_base"]["max_tokens"] = int(input_langchain_chatchat_knowledge_base_max_tokens.value)
config_data["langchain_chatchat"]["knowledge_base"]["prompt_name"] = input_langchain_chatchat_knowledge_base_prompt_name.value
config_data["langchain_chatchat"]["search_engine"]["search_engine_name"] = select_langchain_chatchat_search_engine_search_engine_name.value
config_data["langchain_chatchat"]["search_engine"]["top_k"] = int(input_langchain_chatchat_search_engine_top_k.value)
config_data["langchain_chatchat"]["search_engine"]["model_name"] = input_langchain_chatchat_search_engine_model_name.value
config_data["langchain_chatchat"]["search_engine"]["temperature"] = round(float(input_langchain_chatchat_search_engine_temperature.value), 2)
config_data["langchain_chatchat"]["search_engine"]["max_tokens"] = int(input_langchain_chatchat_search_engine_max_tokens.value)
config_data["langchain_chatchat"]["search_engine"]["prompt_name"] = input_langchain_chatchat_search_engine_prompt_name.value
config_data["zhipu"]["api_key"] = input_zhipu_api_key.value
config_data["zhipu"]["model"] = select_zhipu_model.value
config_data["zhipu"]["top_p"] = input_zhipu_top_p.value
config_data["zhipu"]["temperature"] = input_zhipu_temperature.value
config_data["zhipu"]["history_enable"] = switch_zhipu_history_enable.value
config_data["zhipu"]["history_max_len"] = input_zhipu_history_max_len.value
config_data["zhipu"]["user_info"] = input_zhipu_user_info.value
config_data["zhipu"]["bot_info"] = input_zhipu_bot_info.value
config_data["zhipu"]["bot_name"] = input_zhipu_bot_name.value
config_data["zhipu"]["user_name"] = input_zhipu_user_name.value
config_data["zhipu"]["remove_useless"] = switch_zhipu_remove_useless.value
config_data["bard"]["token"] = input_bard_token.value
config_data["yiyan"]["type"] = select_yiyan_type.value
config_data["yiyan"]["history_enable"] = switch_yiyan_history_enable.value
config_data["yiyan"]["history_max_len"] = int(input_yiyan_history_max_len.value)
config_data["yiyan"]["api"]["api_key"] = input_yiyan_api_api_key.value
config_data["yiyan"]["api"]["secret_key"] = input_yiyan_api_secret_key.value
config_data["yiyan"]["web"]["api_ip_port"] = input_yiyan_web_api_ip_port.value
config_data["yiyan"]["web"]["cookie"] = input_yiyan_web_cookie.value
config_data["tongyi"]["type"] = select_tongyi_type.value
config_data["tongyi"]["cookie_path"] = input_tongyi_cookie_path.value
config_data["tongyixingchen"]["access_token"] = input_tongyixingchen_access_token.value
config_data["tongyixingchen"]["type"] = select_tongyixingchen_type.value
config_data["tongyixingchen"]["history_enable"] = switch_tongyixingchen_history_enable.value
config_data["tongyixingchen"]["history_max_len"] = input_tongyixingchen_history_max_len.value
config_data["tongyixingchen"]["固定角色"]["character_id"] = input_tongyixingchen_GDJS_character_id.value
config_data["tongyixingchen"]["固定角色"]["top_p"] = round(float(input_tongyixingchen_GDJS_top_p.value), 2)
config_data["tongyixingchen"]["固定角色"]["temperature"] = round(float(input_tongyixingchen_GDJS_temperature.value), 2)
config_data["tongyixingchen"]["固定角色"]["seed"] = int(input_tongyixingchen_GDJS_seed.value)
config_data["tongyixingchen"]["固定角色"]["user_id"] = input_tongyixingchen_GDJS_user_id.value
config_data["tongyixingchen"]["固定角色"]["user_name"] = input_tongyixingchen_GDJS_user_name.value
config_data["tongyixingchen"]["固定角色"]["role_name"] = input_tongyixingchen_GDJS_role_name.value
# config_data["my_qianfan"]["model"] = select_my_qianfan_model.value
# config_data["my_qianfan"]["access_key"] = input_my_qianfan_access_key.value
# config_data["my_qianfan"]["secret_key"] = input_my_qianfan_secret_key.value
# config_data["my_qianfan"]["top_p"] = round(float(input_my_qianfan_top_p.value), 2)
# config_data["my_qianfan"]["temperature"] = round(float(input_my_qianfan_temperature.value), 2)
# config_data["my_qianfan"]["penalty_score"] = round(float(input_my_qianfan_penalty_score.value), 2)
# config_data["my_qianfan"]["history_enable"] = switch_my_qianfan_history_enable.value
# config_data["my_qianfan"]["history_max_len"] = int(input_my_qianfan_history_max_len.value)
config_data["my_wenxinworkshop"]["model"] = select_my_wenxinworkshop_model.value
config_data["my_wenxinworkshop"]["api_key"] = input_my_wenxinworkshop_api_key.value
config_data["my_wenxinworkshop"]["secret_key"] = input_my_wenxinworkshop_secret_key.value
config_data["my_wenxinworkshop"]["top_p"] = round(float(input_my_wenxinworkshop_top_p.value), 2)
config_data["my_wenxinworkshop"]["temperature"] = round(float(input_my_wenxinworkshop_temperature.value), 2)
config_data["my_wenxinworkshop"]["penalty_score"] = round(float(input_my_wenxinworkshop_penalty_score.value), 2)
config_data["my_wenxinworkshop"]["history_enable"] = switch_my_wenxinworkshop_history_enable.value
config_data["my_wenxinworkshop"]["history_max_len"] = int(input_my_wenxinworkshop_history_max_len.value)
config_data["gemini"]["api_key"] = input_gemini_api_key.value
config_data["gemini"]["model"] = select_gemini_model.value
config_data["gemini"]["history_enable"] = switch_gemini_history_enable.value
config_data["gemini"]["history_max_len"] = int(input_gemini_history_max_len.value)
config_data["gemini"]["http_proxy"] = input_gemini_http_proxy.value
config_data["gemini"]["https_proxy"] = input_gemini_https_proxy.value
config_data["gemini"]["max_output_tokens"] = int(input_gemini_max_output_tokens.value)
config_data["gemini"]["temperature"] = round(float(input_gemini_max_temperature.value), 2)
config_data["gemini"]["top_p"] = round(float(input_gemini_top_p.value), 2)
config_data["gemini"]["top_k"] = int(input_gemini_top_k.value)
"""
TTS
"""
if True:
config_data["edge-tts"]["voice"] = select_edge_tts_voice.value
config_data["edge-tts"]["rate"] = input_edge_tts_rate.value
config_data["edge-tts"]["volume"] = input_edge_tts_volume.value
config_data["vits"]["type"] = select_vits_type.value
config_data["vits"]["config_path"] = input_vits_config_path.value
config_data["vits"]["api_ip_port"] = input_vits_api_ip_port.value
config_data["vits"]["id"] = input_vits_id.value
config_data["vits"]["lang"] = select_vits_lang.value
config_data["vits"]["length"] = input_vits_length.value
config_data["vits"]["noise"] = input_vits_noise.value
config_data["vits"]["noisew"] = input_vits_noisew.value
config_data["vits"]["max"] = input_vits_max.value
config_data["vits"]["format"] = input_vits_format.value
config_data["vits"]["sdp_radio"] = input_vits_sdp_radio.value
config_data["bert_vits2"]["type"] = select_bert_vits2_type.value
config_data["bert_vits2"]["api_ip_port"] = input_bert_vits2_api_ip_port.value
config_data["bert_vits2"]["model_id"] = int(input_vits_model_id.value)
config_data["bert_vits2"]["speaker_name"] = input_vits_speaker_name.value
config_data["bert_vits2"]["speaker_id"] = int(input_vits_speaker_id.value)
config_data["bert_vits2"]["language"] = select_bert_vits2_language.value
config_data["bert_vits2"]["length"] = round(float(input_bert_vits2_length.value), 2)
config_data["bert_vits2"]["noise"] = round(float(input_bert_vits2_noise.value), 2)
config_data["bert_vits2"]["noisew"] = round(float(input_bert_vits2_noisew.value), 2)
config_data["bert_vits2"]["sdp_radio"] = round(float(input_bert_vits2_sdp_radio.value), 2)
config_data["bert_vits2"]["emotion"] = input_bert_vits2_emotion.value
config_data["bert_vits2"]["style_text"] = input_bert_vits2_style_text.value
config_data["bert_vits2"]["style_weight"] = round(float(input_bert_vits2_style_weight.value), 2)
config_data["bert_vits2"]["auto_translate"] = switch_bert_vits2_auto_translate.value
config_data["bert_vits2"]["auto_split"] = switch_bert_vits2_auto_split.value