-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot.py
58 lines (49 loc) · 1.29 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
# -*- coding: utf-8 -*-
"""ChatBot.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1r_F0WtD5mllbnGUuIqevrml7QrFCKads
"""
pip install nltk
import nltk
from nltk.chat.util import Chat, reflections
pairs = [
[
r"hi|hello|hey",
["Hello!", "Hi there!", "Hey! How can I help you today?"]
],
[
r"not good",
["why, what happen?"]
],
[
r"can you suggest me something?|Something else?",
["Sure, go hear some music", "Sure, go on a lunch date"]
],
[
r"how to be happy?",
["live bro!"]
],
[
r"how are you ?",
["I'm good, thanks for asking.", "I'm doing well. How about you?"]
],
[
r"what is your name ?",
["I'm a chatbot. You can call me Bot.", "I don't have a name, but you can call me bot."]
],
[
r"bye|goodbye|okay,bye",
["Goodbye!", "Bye. Have a great day!"]
],
]
okabot = Chat(pairs, reflections)
print("Bot: Hey, how can I assist you today? Type 'exit' to end- ")
while True:
user_input = input("You: ")
if user_input.lower() == 'exit':
print("bot: Goodbye!")
break
else:
response = bot.respond(user_input)
print("bot:", response)