-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
63 lines (51 loc) · 1.98 KB
/
chatbot.py
File metadata and controls
63 lines (51 loc) · 1.98 KB
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
import random
import webbrowser
class ChatBot:
def __init__(self, name):
self.name = name
self.greetings = ["Hello!", "Hi!", "Hey!" ,]
self.responses = {
"hello": "Hi! How are you?",
"how are you": "I'm good, thanks! How about you?",
"i am fine": "what can i help you",
"what is your name": "My name is " + self.name,
"exit":"goodbye!",
"open youtube": "Opening youtube",
"open instagram": "Opening instagram",
"open zepto": "Opening zepto",
"open amazon": "Opening amazon",
"open chatgpt": "Opening chatgpt",
"open twitter": "Opening twitter"
}
def greet(self):
return random.choice(self.greetings) + ", I'm " + self.name + ". HOW CAN I HELP YOU ?"
def respond(self, message):
message = message.lower()
if message in self.responses:
if message == "open youtube":
webbrowser.open("www.youtube.com")
if message == "open instagram":
webbrowser.open("www.instagram.com")
if message == "open twitter":
webbrowser.open("www.twitter.com")
if message == "open zepto":
webbrowser.open("www.zeptonow.com")
if message == "open amazon":
webbrowser.open("www.amazon.in")
if message == "open chatgpt":
webbrowser.open("www.chatgpt.com")
return self.responses[message]
else:
return "I didn't understand that. Can you plese rephrase?"
def chat(self):
print(self.greet())
while True:
message = input("You: ")
if message.lower() == "exit":
print(self.respond(message))
break
else:
print(self.name + ": " + self.respond(message))
if __name__ == "__main__":
chatbot = ChatBot("pybot")
chatbot.chat()