-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask3.py
More file actions
32 lines (27 loc) · 989 Bytes
/
Copy pathtask3.py
File metadata and controls
32 lines (27 loc) · 989 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
25
26
27
28
29
30
31
32
import nltk
from nltk.tokenize import word_tokenize
# Download NLTK data
nltk.download('punkt')
# Define chatbot responses
responses = {
"hi": "Hello! How can I assist you?",
"how are you": "I'm just a program, so I don't have feelings, but I'm here to help!",
# Add more predefined responses here
}
def preprocess_input(user_input):
tokens = word_tokenize(user_input.lower())
# Additional preprocessing steps if needed
return tokens
def chatbot_response(user_input):
tokens = preprocess_input(user_input)
for query, response in responses.items():
if any(token in query for token in tokens):
return response
return "I didn't understand. Can you please rephrase?"
if __name__ == "__main__":
while True:
user_query = input("You: ")
if user_query.lower() == "exit":
print("Chatbot: Goodbye!")
break
print("Chatbot:", chatbot_response(user_query))