-
Notifications
You must be signed in to change notification settings - Fork 0
/
pocket_advisor_gui.py
109 lines (95 loc) · 3.18 KB
/
pocket_advisor_gui.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
from PyQt5.QtWidgets import *
from chat_bot import ChatBot
from speech_to_text import SpeechToText
from text_to_speech import TextToSpeech
import asyncio
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class PocketAdvisorGUI(QDialog):
def __init__(self):
super().__init__()
self.setStyleSheet("""
QToolButton {
width: 50;
height: 50;
text-align: center;
}
QLineEdit {
padding: 10;
}
QDialog {
background-color: rgb(51, 51, 51);
}
""")
layout = QVBoxLayout()
self.browser = QTextBrowser()
self.browser.setStyleSheet("""
color: white;
font-size: 15px;
background-color: rgb(81, 81, 81);
""")
self.browser.openExternalLinks()
self.mic_icon = QToolButton(icon=QIcon("microphone.png"))
self.mute_icon = QPushButton("muted.png")
self.message_box = QLineEdit()
self.button_layout = QHBoxLayout()
self.button_layout.addWidget(self.mic_icon)
layout.addWidget(self.browser)
layout.addLayout(self.button_layout)
layout.addWidget(self.message_box)
self.setLayout(layout)
self.setWindowTitle("Pocket Advisor")
self.resize(300, 600)
self.move(200, 0)
self.message_box.setFocus()
self.first_message = True
self.con_id = None
self.auth_token = None
self.greeting()
# Connections
self.message_box.returnPressed.connect(self.send_message)
self.mic_icon.clicked.connect(self.send_voice)
def send_message(self):
try:
message = self.message_box.text()
self.browser.append("<p>You: " + message + "</p>")
self.message_box.clear()
self.receive_message(message)
except Exception as e:
print(e)
def receive_message(self, message):
try:
chat_bot = ChatBot(message)
if self.con_id is None:
response = chat_bot.send_message(self.first_message)
else:
response = chat_bot.send_message(self.first_message, self.con_id)
output = response[0]
self.con_id = response[1]
self.browser.append("<p>Agent: " + output + "</p>")
self.first_message = False
TextToSpeech(output)
except Exception as e:
print(e)
def send_voice(self):
try:
result = SpeechToText().run(self.auth_token)
output = result[0]
self.auth_token = result[1]
print(self.auth_token)
self.browser.append("You: " + output)
print(output)
self.receive_message(output)
except Exception as e:
print(e)
def greeting(self):
try:
chat_bot = ChatBot(None)
response = chat_bot.send_message(self.first_message)
output = response[0]
self.con_id = response[1]
self.browser.append("<p>Agent: " + output+"</p>")
self.first_message = False
TextToSpeech(output)
except Exception as e:
print(e)