-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic Chatbot.py
102 lines (94 loc) · 2.35 KB
/
Basic 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
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 10 19:05:23 2024
@author: Sawan Kumar
"""
import nltk
from nltk.chat.util import Chat, reflections
#nltk.download('punkt')
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 chatbot created by Sawan Kumar. You can call me ChatGPT.",]
],
[
r"how are you ?",
["I'm doing good. How about You?",]
],
[
r"(.*) fine",
["Nice to hear!",]
],
[
r"sorry (.*)",
["Its alright","Its OK, never mind",]
],
[
r"i'm (.*) doing good",
["Nice to hear that","Alright :)",]
],
[
r"(.*) age?",
["I'm a computer program, I don't have an age.",]
],
[
r"what (.*) want ?",
["Make me an offer I can't refuse.",]
],
[
r"(.*) created ?",
["I was created by Sawan Kumar.",]
],
[
r"(.*) (location|city) ?",
["I'm based in the cloud.",]
],
[
r"how is the weather in (.*)?",
["Weather in %1 is always great.",]
],
[
r"quit",
["Bye for now. See you soon :) ","It was nice talking to you. See you soon :)"]
],
]
reflections = {
"i am" : "you are",
"i was" : "you were",
"i" : "you",
"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"
}
chatbot = Chat(pairs, reflections)
def chat():
print("Hi, how can I help? \n<<< Type 'quit' to exit. >>>\n")
while True:
user_input = input("User[🧑]: ")
if user_input.lower() == "quit":
print("ChatBot[🤖]: Bye for now. See you soon :)\n")
break
response = chatbot.respond(user_input)
if response:
print("ChatBot[🤖]:",response,"\n")
else:
print("ChatBot[🤖]: Sorry, I am unable to understand.\n")
if __name__ == "__main__":
chat()