Мое окно зависает в то время как l oop как я могу это исправить или как ждать ввода в l oop, если я добавляю ввод (""), что-то программа больше не зависает, но я не хочу использовать консоль.
from ibm_watson import AssistantV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import sys
from PyQt5 import QtWidgets
class Pencere(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.gr=0
self.say=0
self.yazi_alani=QtWidgets.QLineEdit()
self.send=QtWidgets.QPushButton("Send")
self.cevap=QtWidgets.QLabel("")
v_box=QtWidgets.QVBoxLayout()
h_box=QtWidgets.QHBoxLayout()
h_box.addStretch()
v_box.addWidget(self.cevap)
v_box.addStretch()
v_box.addWidget(self.yazi_alani)
v_box.addWidget(self.send)
h_box.addLayout(v_box)
self.setLayout(h_box)
self.send.clicked.connect(self.gonder)
self.setGeometry(200,200,500,500)
self.show()
self.watson()
def watson(self):
while self.say==0:
self.say+=1
# Set up Assistant service.
authenticator = IAMAuthenticator('4CpKAKUsLRpYvcUX_nQRR1MGnYM1WqJLUhE4XS-p4B7Y') # replace with API key
service = AssistantV2(
version = '2020-04-01',
authenticator = authenticator
)
service.set_service_url('https://api.eu-gb.assistant.watson.cloud.ibm.com/instances/49abc832-b899-4359-aca3-ea100ceb777a')
assistant_id = '8e3469cd-deaa-465f-8f6d-e1e4cbf7d9c1' # replace with assistant ID
# Create session.
session_id = service.create_session(
assistant_id = assistant_id
).get_result()['session_id']
# Initialize with emptyhi values to start the conversation.
message_input = {'text': ''}
current_action = ''
while current_action != 'end_conversation':
# Clear any action flag set by the previous response.
current_action = ''
# Send message to assistant.
response = service.message(
assistant_id,
session_id,
input = message_input
).get_result()
# Print the output from dialog, if any. Supports only a single
# text response.
if response['output']['generic']:
if response['output']['generic'][0]['response_type'] == 'text':
self.cevap.setText(response['output']['generic'][0]['text'])
# Check for client actions requested by the assistant.
if 'actions' in response['output']:
if response['output']['actions'][0]['type'] == 'client':
current_action = response['output']['actions'][0]['name']
# If we're not done, prompt for next round of input.
if current_action != 'end_conversation':
user_input=self.yazi_alani.text()
message_input = {
'text': user_input
}
# We're done, so we delete the session.
service.delete_session(
assistant_id = assistant_id,
session_id = session_id
)
def gonder(self):
return self.yazi_alani.text()
app=QtWidgets.QApplication(sys.argv)
pencere=Pencere()
sys.exit(app.exec_())
В этом коде я использую окно ввода больше не зависает, я не хочу использовать консоль
как я могу это исправить или что-то
if current_action != 'end_conversation':
input("->")
user_input=self.yazi_alani.text()
message_input = {
'text': user_input
}