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 23ff54e

Browse files
Update Task5
1 parent 8add732 commit 23ff54e

File tree

1 file changed

+25
-17
lines changed
  • Shashmitha Parvathaneni

1 file changed

+25
-17
lines changed

‎Shashmitha Parvathaneni/Task5

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
## chatbot
22
import nltk
33
from nltk.chat.util import Chat, reflections
4-
# Define the patterns and responses
4+
import webbrowser
5+
import subprocess
6+
7+
# Define some patterns and responses
58
patterns = [
6-
(r'hi|hello|hey', ['Hello!', 'Hi there!', 'Hey!']),
7-
(r'how are you?', ['I am good, thank you!', 'I am doing well, thank you for asking.']),
8-
(r'your name?', ['I am a chatbot.', 'My name is Chatbot.']),
9-
(r'(weather|temperature) (.*)', ['I am sorry, I cannot provide weather information.']),
10-
(r'quit', ['Bye!', 'Goodbye!', 'See you later.'])
9+
(r'hello|hi|hey', ['Hello!', 'Hi there!']),
10+
(r'how are you', ['I am doing well, thank you!']),
11+
(r'what can you do', ['I can provide information and open applications. Just ask!']),
12+
(r'open (.+)', ['Opening {0}...', lambda x: open_application(x[0])])
1113
]
12-
# Create the chatbot
14+
15+
# Function to open applications
16+
def open_application(app_name):
17+
if app_name.lower() == 'calculator':
18+
subprocess.Popen('calc.exe')
19+
elif app_name.lower() == 'notepad':
20+
subprocess.Popen('notepad.exe')
21+
else:
22+
webbrowser.open(app_name + '.com')
23+
24+
# Create a chatbot
1325
chatbot = Chat(patterns, reflections)
14-
def simple_chat():
15-
print("Chatbot: Hi! How can I help you today?")
16-
while True:
17-
user_input = input("You: ")
18-
response = chatbot.respond(user_input)
19-
print("Chatbot:", response)
20-
if user_input.lower() == 'quit':
21-
break
2226

23-
if __name__ == "__main__":
24-
simple_chat()
27+
# Start the conversation
28+
print("Welcome! How can I help you?")
29+
while True:
30+
user_input = input("You: ")
31+
response = chatbot.respond(user_input)
32+
print("Bot:", response)

0 commit comments

Comments
(0)

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