-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI-POWERED-CHATBOT-USING-NLP
More file actions
24 lines (21 loc) · 815 Bytes
/
AI-POWERED-CHATBOT-USING-NLP
File metadata and controls
24 lines (21 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import nltk
from nltk.chat.util import Chat, reflections
# Define chatbot responses (patterns and responses)
pairs = [
(r"hi|hello|hey", ["Hello!", "Hi there!", "Hey!"]),
(r"how are you?", ["I'm good, how about you?", "I'm doing well, thanks for asking!"]),
(r"what is your name?", ["I'm a chatbot!", "I am your virtual assistant."]),
(r"bye|goodbye", ["Goodbye!", "See you soon!", "Take care!"]),
(r"(.*)", ["I'm sorry, I don't understand.", "Can you rephrase that?"])
]
# Initialize chatbot
chatbot = Chat(pairs, reflections)
# Run chatbot
print("Chatbot: Hello! Type 'bye' to exit.")
while True:
user_input = input("You: ")
if user_input.lower() == "bye":
print("Chatbot: Goodbye!")
break
response = chatbot.respond(user_input)
print(f"Chatbot: {response}")