-
Notifications
You must be signed in to change notification settings - Fork 0
/
AI Assistant.py
245 lines (207 loc) · 8.99 KB
/
AI Assistant.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
def main():
import pyttsx3
import datetime
import pywhatkit as kit
from AppOpener import run
import time
import requests
import subprocess
import smtplib
import wikipedia
import googlesearch
import googlesearch
from googlesearch import search
engine = pyttsx3.init()
engine.setProperty('rate', 130)
engine.setProperty('volume', 2.0)
engine.runAndWait()
def speak(audio):
engine.say(audio)
engine.runAndWait()
speak("Hello I am Gokul, an AI-powered virtual assistant. To get started, please type your name:")
user = input("Type your name: ")
def greet_user():
hour = datetime.datetime.now().hour
if hour >= 0 and hour < 12:
speak(f"Good morning, {user}")
elif hour >= 12 and hour < 17:
speak(f"Good afternoon, {user}")
else:
speak(f"Good evening, {user}")
greet_user()
def robot():
if __name__ == "__main__":
if True:
speak(f"How can I assist you, {user}")
query = input("How can I assist you : ").lower()
if "notepad" in query:
try:
speak("Opening Notepad")
subprocess.Popen("notepad")
except:
speak("Unknown error occurred")
elif "spotify" in query:
try:
speak("Opening Spotify")
subprocess.Popen("Spotify")
except:
speak("Unknown error occurred")
elif "word" in query:
try:
speak("opening word")
subprocess.Popen("word")
except:
speak("Unknown error occurred")
elif "whatsapp" in query:
try:
speak("opening whatsapp")
run("WhatsApp")
except:
subprocess.Popen("Unknown error occurred")
elif "netflix" in query:
try:
speak("opening netflix")
subprocess.Popen("Netflix")
except:
speak("Unknown error occurred")
elif "play on youtube" in query:
try:
speak("What do you want to play on YouTube?")
req = input("Enter your request: ") # Use input() to get text input from the user
kit.playonyt(req)
except Exception as e:
speak("Unknown error occurred")
print(e)
elif "date" in query:
try:
speak(datetime.date.today())
except:
speak("Unknown error occurred")
elif "time" in query:
try:
speak(time.strftime("%H:%M:%S", time.localtime()))
except:
speak("Unknown error occurred")
elif "file explorer" in query:
try:
speak("opening file explorer")
subprocess.Popen("file explorer")
except:
speak("Unknown error occurred")
elif "calculater" in query:
try:
speak("opening calculater")
subprocess.Popen("calculator")
except:
speak("Unknown error occurred")
elif "camera" in query:
try:
speak("opening camera")
subprocess.Popen("camera")
except:
speak("Unknown error occurred")
elif "settings" in query:
try:
speak("opening settings")
subprocess.Popen("settings")
except:
speak("Unknown error occurred")
elif "vlc" in query:
try:
speak("opening vlc")
subprocess.Popen("vlc media player")
except:
speak("Unknown error occurred")
elif "chrome" in query:
try:
speak("opening chrome")
subprocess.Popen("google chrome")
except:
speak("Unknown error occurred")
elif "message" in query:
try:
speak(
"Sure, please type the number with the country code to whom I have to message")
number = (input("Enter the Number here"))
speak("now enter the message you want to send")
msg = input("Enter the message here")
kit.sendwhatmsg_instantly(number, msg)
except:
speak("Unknown error occurred")
elif "joke" in query:
try:
def joke():
headers = {'Accept': 'application/json'}
res = requests.get(
"https://icanhazdadjoke.com/", headers=headers).json()
return res["joke"]
jokee = joke()
speak(jokee)
print(jokee)
except:
speak("Unknown error occurred")
elif "advice" in query:
try:
def advice():
res = requests.get(
"https://api.adviceslip.com/advice").json()
return res["slip"]["advice"]
advicee = advice()
speak(advicee)
print(advicee)
except:
speak("Unknown error occurred")
elif " email" in query:
try:
senderEmailId = input("Please type your email address ")
senderPassword = input("Please type the password ")
receiver = input("Enter receivers email address ")
li = [senderEmailId, receiver]
for des in li:
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(senderEmailId, senderPassword)
message = "Message_you_need_to_send"
s.sendmail("sender_email_id", des, message)
s.quit()
except:
speak("Unknown error occurred")
# ...
else:
try:
speak("I found this on the web")
user_query = input("What would you like to search for on the web? ")
# Wikipedia Search
wikipedia_summary = wikipedia.summary(user_query, sentences=5)
print(wikipedia_summary)
speak(wikipedia_summary)
# Google Search
num_page = 3
search_results = googlesearch.search(user_query, num_page)
for result in search_results:
print(result.description)
speak(result.description)
except Exception as e:
speak("Unknown error occurred")
print(e)
# ...
robot()
while True:
speak("Would you like to run this tool again? (yes/no)")
query = input().lower()
if query in ["yes", "yep", "yup", "sure"]:
speak(f"Very well. What else would you like me to do?, {user}")
robot()
elif query in ["no", "not now", "nope", "nah"]:
speak(f"Cool. Thanks for using the program, {user}")
print(f"Cool. Thanks for using the program.", user)
hour = datetime.datetime.now().hour
if 22 <= hour < 6:
speak(f"Good night, {user}")
else:
speak(f"Have a good day, {user}")
print(f"Have a good day, {user}")
break
else:
speak(f"That may be beyond my abilities at the moment. I'm Sorry {user}")
main()