-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatbot.py
143 lines (137 loc) · 3.86 KB
/
Chatbot.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
from tkinter import *
import nltk
from nltk.chat.util import Chat, reflections
root = Tk()
root.title("Chatbot")
def send():
send = "You -> "+e.get()
txt.insert(END, "n"+send)
user = e.get().lower()
if(user == "hello"):
txt.insert(END, "n" + "Bot -> Hi")
elif(user == "hi" or user == "hii" or user == "hiiii"):
txt.insert(END, "n" + "Bot -> Hello")
elif(e.get() == "how are you"):
txt.insert(END, "n" + "Bot -> fine! and you")
elif(user == "fine" or user == "i am good" or user == "i am doing good"):
txt.insert(END, "n" + "Bot -> Great! how can I help you.")
else:
txt.insert(END, "n" + "Bot -> Sorry! I dind't got you")
e.delete(0, END)
txt = Text(root)
txt.grid(row=0, column=0, columnspan=2)
e = Entry(root, width=100)
e.grid(row=1, column=0)
send = Button(root, text="Send", command=send).grid(row=1, column=1)
root.mainloop()
reflections = {
"i am" : "you are",
"i was" : "you were",
"i" : "you",
"i'm" : "you are",
"i'd" : "you would",
"i've" : "you have",
"i'll" : "you will",
"my" : "your",
"you are" : "I am",
"you were" : "I was",
"you've" : "I have",
"you'll" : "I will",
"your" : "my",
"yours" : "mine",
"you" : "me",
"me" : "you"
}
pairs = [
[
r"my name is (.*)",
["Hello %1, How are you today ?",]
],
[
r"hi|hey|hello",
["Hello", "Hey there",]
],
[
r"what is your name ?",
["I am a bot created by Codingwithsagar. you can call me crazy!",]
],
[
r"how are you ?",
["I'm doing goodnHow about You ?",]
],
[
r"I'm also good",
["How can i help you ?",]
],
[
r"sorry (.*)",
["Its alright","Its OK, never mind",]
],
[
r"I am fine",
["Great to hear that, How can I help you?",]
],
[
r"i'm (.*) doing good",
["Nice to hear that","How can I help you?:)",]
],
[
r"(.*) age?",
["I'm a computer program dudenSeriously you are asking me this?",]
],
[
r"what (.*) want ?",
["Make me an offer I can't refuse",]
],
[
r"(.*) created ?",
["Sagar created me using Python's NLTK library ","top secret ;)",]
],
[
r"(.*) (location|city) ?",
['Nagour, Maharashtra',]
],
[
r"how is weather in (.*)?",
["Weather in %1 is awesome like always","Too hot man here in %1","Too cold man here in %1","Never even heard about %1"]
],
[
r"i work in (.*)?",
["%1 is an Amazing company, I have heard about it. But they are in huge loss these days.",]
],
[
r"(.*)raining in (.*)",
["No rain since last week here in %2","Damn its raining too much here in %2"]
],
[
r"how (.*) health(.*)",
["I'm a computer program, so I'm always healthy ",]
],
[
r"(.*) (sports|game) ?",
["I'm a very big fan of Football",]
],
[
r"who (.*) sportsperson ?",
["Messy","Ronaldo","Roony"]
],
[
r"who (.*) (moviestar|actor)?",
["Brad Pitt"]
],
[
r"i am looking for online guides and courses to learn data science, can you suggest?",
["Crazy_Tech has many great articles with each step explanation along with code, you can explore"]
],
[
r"quit",
["BBye take care. See you soon :) ","It was nice talking to you. See you soon :)"]
],
]
def chat():
print("Hi! I am a chatbot created by Codingwithsagar for your service")
chat = Chat(pairs, reflections)
chat.converse()
#initiate the conversation
if __name__ == "__main__":
chat()