-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
124 lines (97 loc) · 3.35 KB
/
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from PySide2.QtGui import QIcon,QColor
from requests import Session
import nltk
import sys
import restfulChat
import botSql
#store the state of the program
states = {
"tag":"",
"isregistered":False,
"issubmitting":False,
"user" : {"name":"","age":0,"tel":"","qual":"","course":""}
}
name = 'You' # Enter your name here!
server = Session()
# GUI:
app = QApplication([])
text_area = QTextEdit()
text_area.setFocusPolicy(Qt.NoFocus)
message = QLineEdit()
layout = QVBoxLayout()
layout.addWidget(text_area)
layout.addWidget(message)
window = QWidget()
window.setLayout(layout)
window.setWindowTitle("Chat Bot")
window.setWindowIcon(QIcon("logo.png"))
window.setGeometry(300, 100, 500, 700)
window.show()
def display_bot_response(msg):
text_area.append(f"Bot :\n{msg}\n")
def validate_response(response):
response, tag = response
states["tag"] = tag
if(tag == "greeting"):
display_bot_response(response)
elif(tag == "plan"):
display_bot_response(response)
elif(tag == "registration"):
if(not states["isregistered"]):
#request user information
states["issubmitting"] =True
states["isregistered"] = True
display_bot_response("Please enter your name")
else:
display_bot_response("You are already registered")
else:
display_bot_response(response)
print(states)
def get_bot_reponse(msg):
response = restfulChat.Bot(msg)
validate_response(response)
# Event handlers:
def get_new_messages():
if(message.text() == "quit"):
sys.exit(0)
else:
if(states['issubmitting']):
if(states["tag"] == "registration"):
if(states["user"]["name"] == ""):
states["user"]["name"] = message.text()
display_bot_response("Please enter your age")
elif(states["user"]["age"] == 0):
states["user"]["age"] = int(message.text())
display_bot_response("Please enter your contact number")
elif(states["user"]["tel"] == ""):
states["user"]["tel"] = message.text()
display_bot_response("What is your highest qualification?")
elif(states["user"]["qual"] == ""):
states["user"]["qual"] = message.text()
display_bot_response("What course do you expect to join?")
elif(states["user"]["course"] == ""):
states["user"]["course"] = message.text()
states["issubmitting"] = False
name,age,tel,qual,course = states['user'].values()
id = botSql.registration(name, age,tel,qual,course)
display_bot_response(f"Your registration number is {id}")
else:
text_area.append(f"You :\n{message.text()}\n")
get_bot_reponse(message.text())
message.clear()
#display the user text
'''
new_message = message.text()
if new_message:
text_area.append("You : "+new_message)
if(message.text() == "quit"):
sys.exit(0)
else:
get_bot_reponse()
message.clear()
'''
# Fire a Enter event
message.returnPressed.connect(get_new_messages)
app.exec_()