arslanasghar6637 commited on
Commit
766d5fe
·
verified ·
1 Parent(s): b4716c7

Create .PY

Browse files
Files changed (1) hide show
  1. .PY +28 -0
.PY ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import nltk
2
+ from nltk.chat.util import Chat, reflections
3
+
4
+ # Define a set of patterns and responses
5
+ pairs = [
6
+ (r'hi|hello|hey', ['Hello!', 'Hi there!', 'Hey!']),
7
+ (r'how are you?', ['I am good, how are you?', 'I am fine, thank you!']),
8
+ (r'what is your name?', ['I am a chatbot, I don’t have a name, but you can call me Chatbot.']),
9
+ (r'bye|exit|quit', ['Goodbye!', 'See you later!', 'Have a nice day!']),
10
+ (r'(.*)', ['Sorry, I did not understand that. Can you please rephrase?'])
11
+ ]
12
+
13
+ # Create a chatbot
14
+ chatbot = Chat(pairs, reflections)
15
+
16
+ # Start the conversation
17
+ def chat():
18
+ print("Chatbot: Hello! Type 'quit' to end the conversation.")
19
+ while True:
20
+ user_input = input("You: ")
21
+ if user_input.lower() in ['quit', 'exit']:
22
+ print("Chatbot: Goodbye!")
23
+ break
24
+ response = chatbot.respond(user_input)
25
+ print("Chatbot:", response)
26
+
27
+ if __name__ == "__main__":
28
+ chat()