Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 43b40ce

Browse files
Create chatbot.py
1 parent 375151d commit 43b40ce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎R.LOKESH/task7/chatbot.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import nltk
2+
from nltk.chat.util import Chat, reflections
3+
4+
# Define pairs of patterns and responses
5+
pairs = [
6+
(r"hi|hello|hey", ["Hello!", "Hi there!", "Hey!"]),
7+
(r"how are you?", ["I'm doing well, thank you!", "I'm good, thanks for asking."]),
8+
(r"what is your name?", ["My name is Chatbot.", "I'm Chatbot, nice to meet you!"]),
9+
(r"bye|goodbye", ["Goodbye!", "See you later!", "Bye!"]),
10+
(r"(.*)", ["I'm sorry, I don't understand."])
11+
]
12+
13+
# Create a chatbot using the defined pairs
14+
chatbot = Chat(pairs, reflections)
15+
16+
# Start the conversation loop
17+
print("Chatbot: Hello! I'm Chatbot. How can I help you today?")
18+
while True:
19+
user_input = input("You: ")
20+
response = chatbot.respond(user_input)
21+
print("Chatbot:", response)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /