forked from Minami-Yuduru/-ChatGPT_VITS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreal_basic_UI.py
311 lines (282 loc) · 12.6 KB
/
real_basic_UI.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
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'real_basic.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
#Qt多媒体用于播放音乐
import time
import sys
import import_UI
from PyQt5 import QtCore, QtGui, QtWidgets #QtMultimedia
import chatgpt_main
import use_main
import pygame
import choosebg
import choose_VITS_model
#全局变量
convers_text_from_import_UI = '' #文本中转
all_text = '' #所有文本
Thread_1_is_running = False #播放音乐多进程状态
Backgroud_jpg_path = '' #图片地址中转
speaker = ''
path_of_pth = ''
path_of_json = ''
model_type = ''
speaker_index = ''
VITS_CLASS_EXIST = False
CALL_NAME = ''
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1319, 759)
Form.setFixedSize(1319, 759)
self.label_API = QtWidgets.QLabel(Form)
self.label_API.setGeometry(QtCore.QRect(800, 20, 90, 30))
self.lineedit = QtWidgets.QLineEdit(Form)
self.lineedit.setGeometry(QtCore.QRect(890, 25, 200, 20))
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(470, 10, 311, 61))
self.label.setStyleSheet("color:rgb(18, 0, 153);\n"
"\n"
"font: 75 20pt \"Segoe Print\";\n"
"")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(0, 60, 1319, 700))
self.label_2.setText("")
self.label_2.setPixmap(QtGui.QPixmap("./picture/001.jpg"))
self.label_2.setScaledContents(True)
self.label_2.setObjectName("label_2")
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(30, 20, 91, 31))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.clicked_push_button)
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(130, 20, 81, 31))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_2.clicked.connect(self.clicked_push_button_2)
self.pushButton_3 = QtWidgets.QPushButton(Form)
self.pushButton_3.setGeometry(QtCore.QRect(1200, 20, 51, 31))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_3.clicked.connect(self.clicked_push_button_3)
self.pushButton_4 = QtWidgets.QPushButton(Form)
self.pushButton_4.setGeometry(QtCore.QRect(220, 20, 101, 31))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_4.clicked.connect(self.clicked_push_button_4)
self.pushButton_5 = QtWidgets.QPushButton(Form)
self.pushButton_5.setGeometry(QtCore.QRect(330, 20, 111, 31))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_5.clicked.connect(self.clicked_push_button_5)
self.plainTextEdit = QtWidgets.QPlainTextEdit(Form)
self.plainTextEdit.setGeometry(QtCore.QRect(160, 590, 511, 87))
self.plainTextEdit.setObjectName("plainTextEdit")
self.label_3 = QtWidgets.QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(160, 490, 511, 71))
self.label_3.setStyleSheet("font: 12pt \"Arial\";background-color: rgba(255, 255, 255, 0.5);")
self.label_3.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.label_3.setWordWrap(True)
self.label_3.setObjectName("label_3")
self.pushButton_6 = QtWidgets.QPushButton(Form)
self.pushButton_6.setGeometry(QtCore.QRect(700, 600, 71, 71))
self.pushButton_6.setObjectName("pushButton_6")
self.pushButton_6.clicked.connect(self.clicked_push_button_6)
self.pushButton_7 = QtWidgets.QPushButton(Form)
self.pushButton_7.setGeometry(QtCore.QRect(700, 490, 71, 71))
self.pushButton_7.setStyleSheet("background-color: rgba(255, 255, 255, 0);")
self.pushButton_7.setText("")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("./picture/play1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_7.setIcon(icon)
self.pushButton_7.setIconSize(QtCore.QSize(50, 50))
self.pushButton_7.setObjectName("pushButton_7")
self.pushButton_7.clicked.connect(self.play_music)
self.textBrowser = QtWidgets.QTextBrowser(Form)
self.textBrowser.setGeometry(QtCore.QRect(920, 90, 311, 581))
self.textBrowser.setStyleSheet("background-color: rgba(255, 255, 255, 0.5);")
#self.textBrowser.setLineWrapMode(QtWidgets.QTextEdit.FixedColumnWidth) #竖直输出
self.textBrowser.setObjectName("textBrowser")
self.label_4 = QtWidgets.QLabel(Form)
self.label_4.setGeometry(QtCore.QRect(-60, 0, 931, 761))
self.label_4.setText("")
self.label_4.setPixmap(QtGui.QPixmap("./picture/81546755.png"))
self.label_4.setScaledContents(False)
self.label_4.setAlignment(QtCore.Qt.AlignCenter)
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Form)
self.label_5.setGeometry(QtCore.QRect(160, 680, 311, 41))
self.label_5.setStyleSheet("font: 14pt \"楷体\";")
self.label_5.setTextFormat(QtCore.Qt.RichText)
self.label_5.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.label_5.setObjectName("label_5")
self.label_API.raise_()
self.lineedit.raise_()
self.label_2.raise_()
self.label_4.raise_()
self.label.raise_()
self.pushButton.raise_()
self.pushButton_2.raise_()
self.pushButton_3.raise_()
self.pushButton_4.raise_()
self.pushButton_5.raise_()
self.plainTextEdit.raise_()
self.label_3.raise_()
self.pushButton_6.raise_()
self.pushButton_7.raise_()
self.textBrowser.raise_()
self.label_5.raise_()
#音乐播放器(有问题)
'''
self.player = QtMultimedia.QMediaPlayer(Form)
self.player.setObjectName('player')
self.player.setVolume(60)
self.player.setMedia(QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile('./audio/audio.wav')))
'''
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "ChatGPT-VITS"))
self.label.setText(_translate("Form", "ChatGPT-VITS"))
self.label_API.setText(_translate('Form','OpenAI API'))
self.lineedit.setText(_translate('Form', chatgpt_main.openai.api_key))
self.pushButton.setText(_translate("Form", "修改背景"))
self.pushButton_2.setText(_translate("Form", "添加设定"))
self.pushButton_3.setText(_translate("Form", "重置"))
self.pushButton_4.setText(_translate("Form", "修改人物立绘"))
self.pushButton_5.setText(_translate("Form", "修改VITS模型"))
self.plainTextEdit.setPlaceholderText(_translate("Form", "请输入对话内容"))
self.label_3.setText(_translate("Form", "请注意导入初始设定"))
self.pushButton_6.setText(_translate("Form", "发送"))
self.label_5.setText(_translate("Form", "输入设定请勿使用此对话框"))
Form.setWindowIcon(QtGui.QIcon('./picture/winicon.ico'))
def clicked_push_button(self):
global Backgroud_jpg_path
choosebg1 = QtWidgets.QDialog()
Widget_choosebg = choosebg.Ui_Choosebg(choosebg1)
Widget_choosebg.setupUi()
Widget_choosebg.Choosebg.exec()
if Backgroud_jpg_path == '':
pass
else:
self.label_2.setPixmap(QtGui.QPixmap(Backgroud_jpg_path))
Backgroud_jpg_path = ''
def clicked_push_button_3(self):
global all_text
all_text = ''
self.textBrowser.setText(all_text)
def clicked_push_button_4(self):
global Backgroud_jpg_path
chooselh1 = QtWidgets.QDialog()
Widget_chooselh = choosebg.Ui_Choosebg(chooselh1)
Widget_chooselh.setupUi()
Widget_chooselh.Choosebg.exec()
if Backgroud_jpg_path == '':
pass
else:
self.label_4.setPixmap(QtGui.QPixmap(Backgroud_jpg_path))
Backgroud_jpg_path = ''
def clicked_push_button_5(self):
global speaker,path_of_json,path_of_pth
choose_VITS = QtWidgets.QDialog()
Widget_choose_VITS = choose_VITS_model.Ui_Dialog(choose_VITS)
Widget_choose_VITS.setupUi()
Widget_choose_VITS.Choose_VITS_model.exec()
if model_type == '':
pass
elif model_type == 0:
self.path_of_json =path_of_json
self.path_of_pth = path_of_pth
elif model_type == 1:
self.path_of_json =path_of_json
self.path_of_pth = path_of_pth
self.speaker = speaker
def clicked_push_button_6(self):
text = self.plainTextEdit.toPlainText()
chatgpt_main.openai.api_key = self.lineedit.text()
global all_text,speaker,path_of_json,path_of_pth,model_type,speaker_index,VITS_CLASS_EXIST,CALL_NAME
if text == '':
self.label_3.setText('请输入对话内容!')
elif all_text == '':
self.label_3.setText('请先导入初始设定!')
else:
#ChatGPT
self.plainTextEdit.setPlainText('')
prompt0 = text
#resualt 展示了当期结果是否为quit
if CALL_NAME == '':
resualt, all_text, audio_text = chatgpt_main.friend_chat(all_text,prompt0)
else:
resualt, all_text, audio_text = chatgpt_main.friend_chat(all_text, prompt0,call_name=CALL_NAME) #TODO
#if resualt == 'quit':
# break
self.label_3.setText(audio_text)
self.textBrowser.setText(all_text)
#VITS
global VITS_Class
#初始状态
if model_type =='':
#判断全局类是否存在
if VITS_CLASS_EXIST == False:
VITS_Class = use_main.single_speaker_model()
VITS_Class.generate(audio_text)
VITS_CLASS_EXIST = True
else:
VITS_Class.generate(audio_text)
elif model_type == 0:
VITS_Class.generate(audio_text)
elif model_type == 1:
VITS_Class.generate(audio_text,speaker_index=int(speaker_index))
self.play_music()
def clicked_push_button_2(self):
global convers_text_from_import_UI
Dialog1 = QtWidgets.QDialog()
Dialog1_Widget = import_UI.Ui_Dialog(Dialog1)
Dialog1_Widget.setupUi()
Dialog1_Widget.retranslateUi()
#Dialog1.show()
Dialog1_Widget.Dialog.exec() #不要show则是直接将Dialog作为主程序,不可以返回主程序窗口
if str(convers_text_from_import_UI) == '':
pass
else:
global all_text
if all_text == '':
all_text = all_text + str(convers_text_from_import_UI)
else:
all_text = all_text + '\n' + str(convers_text_from_import_UI)
self.textBrowser.setText(all_text)
convers_text_from_import_UI = ''
def play_music(self):
#使用多线程
global Thread_1_is_running
if Thread_1_is_running == True:
pass
else:
Thread_1_is_running = True
self.Thread_1 = Thread_1()
self.Thread_1.start()
#self.player.play()
class Thread_1(QtCore.QThread):
def __init__(self):
super(Thread_1, self).__init__()
def run(self):
pygame.mixer.init()
pygame.mixer.music.load('./audio/audio.wav')
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pass
pygame.mixer.music.unload()
global Thread_1_is_running
Thread_1_is_running = False
class windows(QtWidgets.QWidget):
def __init__(self):
super(windows, self).__init__()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
Form = windows()
Widget = Ui_Form()
Widget.setupUi(Form)
Form.show()
app.exec()